基于索引vs ix的大 pandas 拖放行 [英] pandas drop row based on index vs ix
本文介绍了基于索引vs ix的大 pandas 拖放行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试根据其索引(而不是位置)删除pandas数据框行.
I'm trying to drop pandas dataframe row based on its index (not location).
数据框看起来像
DO
129518 a developer and
20066 responsible for
571 responsible for
85629 responsible for
5956 by helping them
(仅供参考:"DO"是列名)
(FYI: "DO" is a column name)
我想删除索引为571的行,所以我这样做了:
I want to delete the row where its index is 571 so I did:
df=df.drop(df.index[571])
然后我检查 df.ix [571]
then I check df.ix[571]
那到底还有什么呢!
所以我认为好吧,也许索引和ix不同!"
So I thought "ok, maybe index and ix are different!"
In [539]: df.index[571]
17002
我的问题是
1)什么是索引? (与ix相比)
1) What is index? (compared to ix)
2)如何使用ix删除索引行571?
2) How do I delete the index row 571 using ix?
推荐答案
您应该 drop
直接从索引中获得所需的值:
You should drop
the desired value from the index directly:
df.drop(571, inplace=True)
这篇关于基于索引vs ix的大 pandas 拖放行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文