首页 > 其他分享 >pandas中的inplace参数,将变量值赋给inplace= True 的结果,输出为none

pandas中的inplace参数,将变量值赋给inplace= True 的结果,输出为none

时间:2023-03-30 15:11:52浏览次数:37  
标签:none df inplace 赋给 True pandas

pandas中的inplace参数,将变量值赋给inplace= True 的结果,输出为none

#在学习drop函数是遇见将变量值赋给inplace= True 的结果,输出为none

import pandas as pd
import numpy as np

city = pd.DataFrame(np.random.randn(5, 5),
     columns=['shenzhen', 'guangzhou', 'beijing', 'nanjing', 'haerbin'])

print(city)

df3 = city.drop(labels=1,inplace=True,axis=0)
print(df3)
"""
输出结果:
none
"""
#其原因为
#当您使用inplace=True时,将创建并更改新对象,而不是原始数据。如果您希望更新原始数据以反映已删除的行。当你使用inplace=True时,什么也不会返回
#也就是说
#df_2 = df_2.dropna(inplace=False)与df_2.dropna(inplace=True)是等价的,但不能再新建一个变量接受df_2.dropna(inplace=True)

标签:none,df,inplace,赋给,True,pandas
From: https://www.cnblogs.com/yangzilaing/p/17272762.html

相关文章