I have very weird case of a warning appearing quite randomly. EDIT: Please note that this question is not about how to deal with the warning but why it appears/disappears based on what is a single value in a data frame.
I have two files - test1.csv with:
A,B,C
0,-0.7071068,0
and - test2.csv with:
A,B,C
0,0,0
I get the warning
c:\libs\python36-32\lib\site-packages\ipykernel_launcher.py:2:
SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
when using the first file with the code (first file):
df = pd.read_csv("test1.csv")
df['B'][df['B'] > -1] = np.nan
but not with (same code, second file):
df = pd.read_csv("test2.csv")
df['B'][df['B'] > -1] = np.nan
In each case running the code results in suggesting the warning is wrong (the change goes through, so I'm not working with a copy):
A B C
0 0 NaN 0
I'm on Windows 10 with Python 3.6.5 64-bit, Jupyter 4.4.0 and Pandas 0.23.3