Python: Need to find beginning of each trial in dataframe

I have a pandas dataframe of an experiment with multiple trials. The trials are numbered 1-12 and there are multiple rows per trial. I would like to make a column of 1s and 0s where 1 indicates where a trial begins. This is the code I have:

for i in df['Trial Start']:
if df.groupby('Trial Number').head(1):
    i = 1
    i = 0

I am getting the error 'ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all'

I know why I'm getting this error, but I also know there's definitely a better way to do this. Any help is appreciated.

Read more here:

Content Attribution

This content was originally published by TemisA12 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: