I try to create a max_time columns which in row rsvn 1 will have value of 2 (max of status == 'ss' of rsvn 1) and in row rsvn 2 will have value 6.
How can i do that with 1 row of pandas code
I try to create a max_time columns which in row rsvn 1 will have value of 2 (max of status == 'ss' of rsvn 1) and in row rsvn 2 will have value 6.
How can i do that with 1 row of pandas code
# Assuming the data is like this:
df = pd.DataFrame(
{'rsvn': {0: 1, 1: 1, 2: 1, 3: 1, 4: 2, 5: 2, 6: 2, 7: 2},
'status': {0: 'ss', 1: 'ss', 2: 'f', 3: 'f', 4: 'ss', 5: 'ss', 6: 'f', 7: 'f'},
'time': {0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8}}
)
# you can recreate the max_time column like this:
max_df = df[df['status'] == 'ss'].groupby('rsvn')['time'].max().rename('max_time').reset_index()
df.merge(max_df, on='rsvn', how = 'left')