I have a df looking something like this but larger:
df = pd.DataFrame({
'Time' : [1,2,7,10,15,16,77,98,999,1000,1121,1245,1373,1490,1555],
'ID' : ['1', '1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3', '3', '3'],
'Act' : ['1', '2', '4', '4', '2', '0', '2', '4', '4', '1', '4', '4', '1', '1', '2'],
'mean_bout_count' : ['2.3', '4', '7', '7', '1', '2', '2.2', '2.1', '2.1', '10', '3', '3', '3', '3', '3']})
For each row that is "Act_cat" == 4 and "mean_bout_count" < 3 I would like to take -1 from the "Act_cat" column. The code below takes a -1 from all rows as far as I can tell and also takes too long...
df = df.reset_index()
for i, row in df.iterrows():
if df.iloc[i]["Act_cat"] == 4 and df.iloc[i]["mean_bout_count"] < 3:
df["Act_cat"] = df["Act_cat"]-1
else:
df["Act_cat"] = df["Act_cat"]-0
Please let me know if you have a better idea!
Thank you!