我有這個 for 回圈,我想更改 df 的一部分的值。
for col in last_df:
last_df.loc[last_df[col]!=0, col]='stop'
stop=last_df[last_df[col]=='stop'][col].index[0]
last_df[col].loc[:(stop-1)]='NaN'
最后, last_df 沒有修改,我收到的錯誤如下:
A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation:....
uj5u.com熱心網友回復:
嘗試不使用 loc。
for col in last_df:
last_df[last_df[col]!=0]='stop'
stop=last_df[last_df[col]=='stop'][col].index[0]
last_df[col][:(stop-1)]='NaN'
這是 DataFrame 的視圖和副本的問題,有關更多資訊,請快速了解您可以在此鏈接中閱讀
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/424716.html
上一篇:如何在seleniumpython中的h2標簽之間復制到剪貼板文本
下一篇:基于查找表有效替換多列中的字串
