I would like to add a column to an existing dataframe which shows a count value. The count value should compare a value in a given row versus all rows in another column.
In my example I want to find the number of times a value in the entire 'end_date' column is earlier than current 'start_date' column. Adding the count to the dataframe like so:
start_date end_date count
1 2020-09-2 2020-09-3 1
2 2020-09-6 2020-09-7 3
3 2020-09-4 2020-09-5 2
4 2020-09-1 2020-09-1 0
I have tried
df['count'] = (df[df['end_date']<df['start_date']]).count()
but this results in the count column being 0 for all rows as the start_date is always less than the end_date within any one row.