Python Pandas 用 df.drop 删除行不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38481409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas deleting row with df.drop doesn't work
提问by Madddin
I have a DataFrame like this (first column is index
(786...) and second day
(25...) and Rainfall amount
is empty):
我有一个这样的 DataFrame(第一列是index
(786...) 和第二列day
(25...) 并且Rainfall amount
是空的):
Day Rainfall amount (millimetres)
786 25
787 26
788 27
789 28
790 29
791 1
792 2
793 3
794 4
795 5
and I want to delete the row 790. I tried so many things with df.drop but nothin happend.
我想删除第 790 行。我用 df.drop 尝试了很多东西,但什么也没发生。
I hope you can help me.
我希望你能帮助我。
回答by frist
While dropping new DataFrame returns. If you want to apply changes to the current DataFrame you have to specify inplace
parameter.
删除新的 DataFrame 返回时。如果要将更改应用于当前 DataFrame,则必须指定inplace
参数。
Option 1
Assigning back to df
-
选项 1
分配回df
-
df = df.drop(790)
Option 2
Inplace argument -
选项 2
就地参数 -
df.drop(790, inplace=True)