col
one two
a t 0
u 1
v 2
w 3
对于以上结构的两层行索引 DataFrame,采用 data.loc[(c, u), col] 取数据时,一般情况下会触发如下警告:
PerformanceWarning: indexing past lexsort depth may impact performance.
这是因为索引没有排序,而是否排序对 DataFrame 的检索效率有较大影响,只要按如下:
data = data.sort_index()
给索引排个序就可消除该警告。
本文介绍了解决使用pandas处理多层索引DataFrame时出现的性能警告的方法。通过对DataFrame的索引进行排序,可以显著提高数据检索的速度并消除相关警告。
133

被折叠的 条评论
为什么被折叠?



