在pandas
库中很多次都有一个选项来更改对象,例如使用以下语句...
df.dropna(axis='index', how='all', inplace=True)
Run Code Online (Sandbox Code Playgroud)
我很好奇返回的内容以及inplace=True
传递对象时的处理方式inplace=False
.
正在修改的所有操作self
时inplace=True
?什么时候inplace=False
立即创建一个新对象new_df = self
,然后new_df
返回?
I have a pandas dataframe and want to get rid of rows in which the column 'A' is negative. I know 2 ways to do this:
df = df[df['A'] >= 0]
Run Code Online (Sandbox Code Playgroud)
or
selRows = df[df['A'] < 0].index
df = df.drop(selRows, axis=0)
Run Code Online (Sandbox Code Playgroud)
What is the recommended solution? Why?