2
votes

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

1

1 Answers

7
votes

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()