I have a simple process, trying to add the array prob_win
as a new column of an existing data frame df
. They have the same dimension as shown below:
print type(prob_win)
print len(prob_win)
print df.shape
<type 'numpy.ndarray'>
799
(799, 1)
I then did the following assignment:
df['prob_win'] = prob_win
The code works but have the following warning:
1 Warning
/opt/conda/envs/python2/lib/python2.7/site-packages/ipykernel/__main__.py:14: 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: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
So I changed to use .loc as the warning said:
df.loc[:,'prob_win'] = prob_win
But still got the same error. What did I do wrong here? How do I get rid the warning in this case? Thanks!