1.運行一段代碼,出現(xiàn)警示錯誤,但是程序還是正常運行
file_hw = file[file["廠家"] == "華為"]
file_hw["ECI"] = file_hw.loc[:, "ENODEB"].astype(str) + "-" + file_hw.loc[:, "小區(qū)標示"].astype(str)
- 錯誤如下:
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
# 。。歌豺。。心包。类咧。。蟹腾。省略部分錯誤
- 解決方案:
file_hw = file[file["廠家"] == "華為"]
x = file_hw.copy
x["ECI"] = x.loc[:, "ENODEB"].astype(str) + "-" + x.loc[:, "小區(qū)標示"].astype(str)
-
stackoverflow解決方案連接:
https://stackoverflow.com/questions/31468176/setting-values-on-a-copy-of-a-slice-from-a-dataframe?rq=1
# This warning comes because your dataframe x is a copy of a slice. This is not easy to know why, but it has something to do with how you have come to the current state of it.
# You can either create a proper dataframe out of x by doing
x = x.copy()
# This will remove the warning, but it is not the proper way
# You should be using the DataFrame.loc method, as the warning suggests, like this:
x.loc[:,'Mass32s'] = pandas.rolling_mean(x.Mass32, 5).shift(-2)