I am trying to store the contents of a list inside of an empty column in my dataframe called "total_hour_activity" like seen bellow. However, I keep getting an a "setting with copy warning":
timestamp date activity Id total_hour_activity
720 00:00 2003-05-08 0 condition_1 NaN
721 00:01 2003-05-08 0 condition_1 NaN
722 00:02 2003-05-08 0 condition_1 NaN
723 00:03 2003-05-08 0 condition_1 NaN
724 00:04 2003-05-08 0 condition_1 NaN
... ... ... ... ... ...
10795 23:55 2003-05-14 12 condition_1 NaN
10796 23:56 2003-05-14 0 condition_1 NaN
10797 23:57 2003-05-14 18 condition_1 NaN
10798 23:58 2003-05-14 0 condition_1 NaN
10799 23:59 2003-05-14 64 condition_1 NaN
list = []
score = 0;
for i, row in my_df.iterrows():
activity = i
score = score + row['activity']
if (i + 1) % 60 == 0:
list.append(score)
score = 0
my_df['total_hour_activity'] = list
<ipython-input-8-10e7d5921077>: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 caveats in the documentation: https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
my_df['total_hour_activity'] = list
Is there another way to transfer the contents of a list to a dataframe column to avoid this warning?