1
從從csv
文件加載初始數據幀,上過濾大熊貓創建列數據框
df = pd.read_csv("file.csv",sep=";")
我得到一個過濾副本
df_filtered = df[df["filter_col_name"]== value]
然而,使用diff()
方法創建一個新的列時,
df_filtered["diff"] = df_filtered["feature"].diff()
我收到以下警告:
/usr/local/bin/ipython3:1: SettingWithCopyWarning:
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
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
#!/usr/bin/python3
我還注意到處理時間很長。令人驚訝的是(對我來說......),如果我在非過濾的DataFrame上做同樣的事情,我運行良好。
我應該如何繼續在過濾的數據上創建「diff」列?