pandas :.ix的替换 [英] Pandas: Replacement for .ix

查看:58
本文介绍了 pandas :.ix的替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出对熊猫0.20.0的更新和这个问题,但是是第二种选择(不使用.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的替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆