3 回答

TA貢獻1963條經(jīng)驗 獲得超6個贊
如果inplace=True通過,該數(shù)據(jù)被重命名到位(它沒有返回值),所以你會使用:
df.an_operation(inplace=True)
當(dāng)inplace=False傳遞(這是默認值,所以沒有必要),執(zhí)行操作,并返回該對象的副本,所以你會使用:
df = df.an_operation(inplace=False)
所以:
if inplace == False:
Assign your result to a new variable
else
No need to assign

TA貢獻2036條經(jīng)驗 獲得超8個贊
我使用它的方式是
# Have to assign back to dataframe (because it is a new copy)
df = df.some_operation(inplace=False)
要么
# No need to assign back to dataframe (because it is on the same copy)
df.some_operation(inplace=True)
結(jié)論:
if inplace is False
Assign to a new variable;
else
No need to assign

TA貢獻1829條經(jīng)驗 獲得超13個贊
我通常與numpy一起使用。
如果您不想將更新的數(shù)據(jù)保存到同一變量,則使用inplace = True
data["column1"].where(data["column1"]< 5, inplace=True)
這和...一樣
data["column1"] = data["column1"].where(data["column1"]< 5)
添加回答
舉報