如何从Pandas数据框中删除行列表? [英] How to drop a list of rows from Pandas dataframe?
本文介绍了如何从Pandas数据框中删除行列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框df:
>>> df
sales discount net_sales cogs
STK_ID RPT_Date
600141 20060331 2.709 NaN 2.709 2.245
20060630 6.590 NaN 6.590 5.291
20060930 10.103 NaN 10.103 7.981
20061231 15.915 NaN 15.915 12.686
20070331 3.196 NaN 3.196 2.710
20070630 7.907 NaN 7.907 6.459
然后我要删除具有列表中指示的某些序列号的行,假设这里是[1,2,4],
然后离开:
Then I want to drop rows with certain sequence numbers which indicated in a list, suppose here is [1,2,4],
then left:
sales discount net_sales cogs
STK_ID RPT_Date
600141 20060331 2.709 NaN 2.709 2.245
20061231 15.915 NaN 15.915 12.686
20070630 7.907 NaN 7.907 6.459
如何或什么功能可以做到这一点?
How or what function can do that ?
推荐答案
使用 DataFrame.drop 并传递给它一系列索引标签:
Use DataFrame.drop and pass it a Series of index labels:
In [65]: df
Out[65]:
one two
one 1 4
two 2 3
three 3 2
four 4 1
In [66]: df.drop(df.index[[1,3]])
Out[66]:
one two
one 1 4
three 3 2
这篇关于如何从Pandas数据框中删除行列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文