0

I am using the following code:

video_df_x.loc[:, 'duration'] = pd.to_datetime(video_df['datetime_2']) - pd.to_datetime(video_df_x['datetime_1'])

The code runs but gives me the following warning:

C:\Program Files\Anaconda3\lib\site-packages\pandas\core\indexing.py:337: 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

I do not understand why I receive this error, since I am already using .loc in my code, which is recommended in the warning message.

Any insights?

renakre
  • 8,001
  • 5
  • 46
  • 99
  • 2
    that is just a warning as you are trying to create a column. what happens when you add `.copy()` at the end of each dataframe? `pd.to_datetime(video_df['datetime_2'].copy()) - pd.to_datetime(video_df_x['datetime_1'].copy())` – MattR Feb 20 '18 at 18:44
  • 1
    Does this help? https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas My guess is that `video_df_x` is slice of a dataframe, though without the full code I don't know for sure – johnchase Feb 20 '18 at 18:48
  • https://www.dataquest.io/blog/settingwithcopywarning/ See 'Hidden chaining' – Georgy Feb 20 '18 at 19:12
  • Possible duplicate of [Pandas: SettingWithCopyWarning:](https://stackoverflow.com/questions/45170312/pandas-settingwithcopywarning) – Georgy Feb 20 '18 at 19:16

0 Answers0