理解就地=真 [英] Understanding inplace=True

查看:25
本文介绍了理解就地=真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pandas 库中多次有一个选项可以就地更改对象,例如使用以下语句...

In the pandas library many times there is an option to change the object inplace such as with the following statement...

df.dropna(axis='index', how='all', inplace=True)

我很好奇返回的内容以及在传递 inplace=True 时与传递 inplace=False 时对象的处理方式.

I am curious what is being returned as well as how the object is handled when inplace=True is passed vs. when inplace=False.

inplace=True 时,是否所有操作都修改了self?当 inplace=False 是一个立即创建的新对象时,例如 new_df = self 然后返回 new_df ?

Are all operations modifying self when inplace=True? And when inplace=False is a new object created immediately such as new_df = self and then new_df is returned?

推荐答案

inplace=True 被传递时,数据就地重命名(它什么都不返回),所以你会使用:

When inplace=True is passed, the data is renamed in place (it returns nothing), so you'd use:

df.an_operation(inplace=True)

inplace=False 被传递时(这是默认值,所以不是必需的),执行操作并返回对象的副本,所以你会使用:

When inplace=False is passed (this is the default value, so isn't necessary), performs the operation and returns a copy of the object, so you'd use:

df = df.an_operation(inplace=False) 

这篇关于理解就地=真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆