我有一個 Pandas 資料框,我想轉換一些列并將轉換分配回現有的 dtaframe:
df.loc[:,df.columns != 'target'].pct_change(-1)
如果我做:
df.loc[:,df.columns != 'target'] = df.loc[:,df.columns != 'target'].pct_change(-1)
我收到警告:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
找回轉化后的正確方法是什么df?謝謝
uj5u.com熱心網友回復:
你可以做 update
df.update(df.loc[:,df.columns != 'target'].pct_change(-1))
uj5u.com熱心網友回復:
使用 df.filter 過濾掉包含 word target 的列
df[df.filter(regex='[^target]').columns]=df.loc[:,df.filter(regex='[^target]').columns].pct_change(-1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/358439.html
下一篇:根據出現次數按列分組
