-
-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Closed
Description
I get a SettingWithCopyWarning after the use of dropna
, which does not really seem logical:
In [102]: df = pd.DataFrame({'a':[1,2,np.nan], 'b':['A', 'B', 'C']})
In [103]: df
Out[103]:
a b
0 1 A
1 2 B
2 NaN C
In [104]: df = df.dropna(subset=['a'])
In [105]: df
Out[105]:
a b
0 1 A
1 2 B
In [106]: df['new_col'] = 2
C:\Anaconda\envs\devel\Scripts\ipython-script.py: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 the caveats in the documentation: http://pandas.pydata.org/pandas-docs/s
table/indexing.html#indexing-view-versus-copy
if __name__ == '__main__':
In [107]: df.loc[:,'new_col'] = 2
c:\users\vdbosscj\scipy\pandas-joris\pandas\core\indexing.py:404: SettingWithCop
yWarning:
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 the caveats in the documentation: http://pandas.pydata.org/pandas-docs/s
table/indexing.html#indexing-view-versus-copy
self.obj[item] = s
Further, also the indication were the warning occurred is not correct I think.
Metadata
Metadata
Assignees
Labels
No labels