I have a DataFrame with repeating values in the index. I would like to filter this dataset down to only show me one instance of each index by selecting the row within the in
You can perform a groupby
on 'Product ID', then apply idxmax
on 'Sales' column.
This will create a series with the index of the highest values.
We can then use the index values to index into the original dataframe using iloc
In [201]:
df.iloc[df.groupby('Product ID')['Sales'].agg(pd.Series.idxmax)]
Out[201]:
Product_ID Store Sales
1 1 B 200
3 2 A 400
5 3 A 200
8 4 C 500