2

I have a very simple command in pandas like:

volume_related_pd.loc[:,"last_record_volume"] = volume_related_pd.loc[:,"volume"]

I think the complexity is that i have duplicate index. It produces the warning that:

/anaconda2/lib/python2.7/site-packages/pandas/core/indexing.py:601: 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

What shall i do? Thanks. I already use .iloc

user40780
  • 1,828
  • 7
  • 29
  • 50
  • 1
    Possible duplicate of [How to deal with SettingWithCopyWarning in Pandas?](https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas) – Georgy Jan 09 '18 at 15:27

1 Answers1

7

Oh. I figured out... This comes from how the volume_related_pd is initially defined.

Initially it is

volume_related_pd = complete_contract_info_pd[["volume"]]

Then the warning comes.

However, if i specifically define it to be a copy of the original pd, then the problem is gone:

volume_related_pd = complete_contract_info_pd[["volume"]].copy()
user40780
  • 1,828
  • 7
  • 29
  • 50