解决这个问题
C:\Users\DELL\Anaconda3\lib\site-packages\pandas\core\frame.py:2746: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
其实问题不大,只用加一个.copy()到合适的地方就OK啦。
比如,这个动图案例中,出现了
df_interest = df.loc[df['Country/Region'].isin(['United Kingdom', 'US', 'Italy', 'Germany'])& df['Province/State'].isna()]
df_interest.rename(index=lambda x: df_interest.at[x, 'Country/Region'], inplace=True)
df1 = df_interest.transpose()
df1 = df1.drop(['Province/State', 'Country/Region', 'Lat', 'Long'])
df1 = df1.loc[(df1 != 0).any(1)]
到我这里死活过不去,修改了上面两个地方。把第一句换成一下:
df_interest = df.loc[df['Country/Region'].isin(['United Kingdom', 'US', 'Italy', 'Germany'])& df['Province/State'].isnull()].copy()
然后问题就没有了。