我只想修改pandas dataframe列上大于750的值
datf.iloc[:,index][datf.iloc[:,index] > 750] = datf.iloc[:,index][datf.iloc[:,index] > 750]/10.7639我认为语法很好,但是我得到了一个Pandas警告,所以我不知道这样做是否正确:
<ipython-input-24-72eef50951a4>:3: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy在不收到此警告的情况下执行此操作的正确方法是什么?
发布于 2021-02-14 19:49:09
您可以使用apply方法通过自定义函数对列进行修改。注意:您还可以将applymap用于多个列
def my_func(x):
if x > 750:
x= #do your modification
else:
x
return x
new_dta= datf['col_name'].apply(my_func) https://stackoverflow.com/questions/66195056
复制相似问题