本文介绍了Python Pandas:DataFrame过滤负值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何删除列中包含负值的所有索引.我正在使用熊猫DataFrames
.
I was wondering how I can remove all indexes that containing negative values inside their column. I am using Pandas DataFrames
.
格式:
Myid - valuecol1 - valuecol2 - valuecol3 -... valuecol30
Myid - valuecol1 - valuecol2 - valuecol3 -... valuecol30
所以我的DataFrame
被称为data
我知道如何对1列执行此操作:
I know how to do this for 1 column:
data2 = data.index[data['valuecol1'] > 0]
data3 = data.ix[data3]
所以我只能在valuecol1 > 0
处获得ID,如何执行某种and
语句?
So I only get the ids where valuecol1 > 0
, how can I do some kind of and
statement?
valuecol1 && valuecol2 && valuecol3 && ... && valuecol30 > 0
?
推荐答案
您可以遍历列名
for cols in data.columns.tolist()[1:]:
data = data.ix[data[cols] > 0]
这篇关于Python Pandas:DataFrame过滤负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!