微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

pandas df:

 

new_df['tissue'] = new_df['tissue'].str.lower()
<ipython-input-24-d2fb04c89c2a>: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: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  new_df['tissue'] = new_df['tissue'].str.lower()




import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randint(1,10,(4,5)),columns=["A","B","C","D","E"])
print(df)
df_1 = df[["A","B"]].copy()
df_1["A"]= df_1["A"] +1
print("df = ",df)
print("df_1 = ",df_1)



import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randint(1,10,(4,5)),columns=["A","B","C","D","E"])
print(df)
df_1 = df.loc[:,["A","B"]]
df_1["A"]= df_1["A"] +1
print("df = ",df)
print("df_1 = ",df_1)


REF
https://blog.csdn.net/u011406900/article/details/106472809

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐