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
原文地址:https://www.cnblogs.com/emanlee/p/14497914.html