本文介绍了Pandas:替代 .ix的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于pandas 0.20.0 的更新和弃用 .ix
,我想知道使用剩余的 .loc
和 获得相同结果的最有效方法是什么.iloc
.我刚刚回答了这个问题,但第二个选项(不使用 .ix
) 似乎效率低下且冗长.
Given the update to pandas 0.20.0 and the deprecation of .ix
, I am wondering what the most efficient way to get the same result using the remaining .loc
and .iloc
. I just answered this question, but the second option (not using .ix
) seems inefficient and verbose.
片段:
print df.iloc[df.loc[df['cap'].astype(float) > 35].index, :-1]
在使用条件过滤和索引位置过滤时,这是正确的方法吗?
Is this the proper way to go when using both conditional and index position filtering?
推荐答案
通过使用位置对特定索引进行切片来获取所需的索引值,您可以停留在单个 loc
的世界中.
You can stay in the world of a single loc
by getting at the index values you need by slicing that particular index with positions.
df.loc[
df['cap'].astype(float) > 35,
df.columns[:-1]
]
这篇关于Pandas:替代 .ix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!