aa=df1.fillna(0,inplace=True),aa返回结果是none,df1是替换后的dataframe

df1=pd.DataFrame([[1,2,3],[NaN,NaN,2],[NaN,NaN,NaN],[8,8,NaN]])
aa=df1.fillna(0,inplace=True)
print(aa)
print(df1)
为什么aa返回结果是none,而df1是替换后的dataframe?

Jason990420
最佳答案
aa = df1.fillna(0,inplace=True)

inplace:bool, default False
If True, fill in-place.
Note: this will modify any other views on this object (e.g., a no-copy slice for a column in a DataFrame).

In-place (就地运算) 是直接更改给定变量的内容而无需复制的运算。因此方法 fillna 无返回值 (也就是 None ), 所以 aa 为 None; 而代入的变量 df1, 在 fillna 方法后, 内容直接被改变了.

如果想要结果在 aa, 而 df1 内容不被变动, 需设置 inplace=False, 或不设置.

3年前 评论
panyalan (楼主) 3年前
讨论数量: 1
Jason990420
aa = df1.fillna(0,inplace=True)

inplace:bool, default False
If True, fill in-place.
Note: this will modify any other views on this object (e.g., a no-copy slice for a column in a DataFrame).

In-place (就地运算) 是直接更改给定变量的内容而无需复制的运算。因此方法 fillna 无返回值 (也就是 None ), 所以 aa 为 None; 而代入的变量 df1, 在 fillna 方法后, 内容直接被改变了.

如果想要结果在 aa, 而 df1 内容不被变动, 需设置 inplace=False, 或不设置.

3年前 评论
panyalan (楼主) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!