I do not understand why the following code does not work :
df_sensor.loc[(df_sensor.user_id == labels_user_id) & (df_sensor.exp_id == labels_exp_id),'activity_id'].iloc[start:end] = labels['activity_id'][I]
This line
df_sensor.loc[(df_sensor.user_id == labels_user_id) & (df_sensor.exp_id == labels_exp_id),'activity_id'].iloc[start:end]
Return this data frame
I want to change the value where user_id and exp_id from specific index (start and end)
EDIT
I have 2 dataframe
1: Dataframe 1
2: Dataframe 2
I want to change the activity_id of the DF1 from the DF2.activity_id with start and end as an index
Your issue is chained assignment:
df.loc[].iloc[] =which will not change the DataFrame. However your selection is complicated, you want to change a range of values that are determined only after the initial slice.We can define your initial mask and use some math with
cumsumto allow for the same selection with a single.loccall.Sample Data
Code