简体   繁体   中英

SettingWithCopyWarning using loc/iloc doesn't set values

sp_eur.iloc[72][['Open_eur','High_eur','Low_eur','Close_eur','Volume_eur','Dividends_eur','Stock Splits_eur']] = sp_eur.iloc[71][['Open_eur','High_eur','Low_eur','Close_eur','Volume_eur','Dividends_eur','Stock Splits_eur']]

returns this:

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  iloc._setitem_with_indexer(indexer, value)
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/core/series.py:1064: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

More important than the warning is the fact that the operations is not performed and even more important is that the code worked perfectly fine before I restarted the kernel .

The problem here was the slicing of the df and the loc syntax. Here's the proper code:

sp_eur.iloc[72,['Open_eur','High_eur','Low_eur','Close_eur','Volume_eur','Dividends_eur','Stock Splits_eur']] =\ 
sp_eur.iloc[71,['Open_eur','High_eur','Low_eur','Close_eur','Volume_eur','Dividends_eur','Stock Splits_eur']]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM