I have a dataframe as follows:
user num1 num2
a 1 1
a 2 2
a 3 3
b 4 4
b 5 5
I want a dataframe which has the minimum from num1 for each user, and the maximum of num2 for each user.
The output should be like:
user num1 num2
a 1 3
b 4 5
I know that if I wanted the max of both columns I could just do:
a.groupby('user')['num1', 'num2'].max()
Is there some equivalent without having to do something like:
series_1 = a.groupby('user')['num1'].min()
series_2 = a.groupby('user')['num2'].max()
# converting from series to df so I can do a join on user
df_1 = pd.DataFrame(np.array([series_1]).transpose(), index=series_1.index, columns=['num1'])
df_2 = pd.DataFrame(np.array([series_2]).transpose(), index=series_2.index, columns=['num2'])
df_1.join(df_2)