I have the following dataframe.
df = pd.DataFrame(
{
'ID': ['AB01', 'AB01', 'AB01', 'AB02', 'AB02','AB03'],
'ColA': [np.nan, 0.8, 17, np.nan, np.nan, np.nan],
'ColB': [10, 0.8, np.nan, np.nan, 14, np.nan],
'Type': ["A","B","D","C","A",np.nan]
}
I want to get a df which is grouped by ID with the max ColC value for each ID. I wrote this code and got the result, but I need associated column 'Type' as well in the result.
df2 = df.groupby('ID')['ColC'].max().reset_index()
This is the result I got, I want the df2 to have column 'Type' as well. How do I achieve it?