I feel like you’re overthinking this. Just use groupby
and idxmin
:
df.loc[df.groupby('A').B.idxmin()]
A B C
2 1 2 10
4 2 4 4
df.loc[df.groupby('A').B.idxmin()].reset_index(drop=True)
A B C
0 1 2 10
1 2 4 4
More Related Contents:
- How can I pivot a dataframe?
- Get statistics for each group (such as count, mean, etc) using pandas GroupBy?
- How do I create a new column from the output of pandas groupby().sum()?
- GroupBy pandas DataFrame and select most common value
- Pandas GroupBy.apply method duplicates first group
- pandas GroupBy columns with NaN (missing) values
- Count unique values per groups with Pandas [duplicate]
- How to access pandas groupby dataframe by key
- group by pandas dataframe and select latest in each group
- why does pandas rolling use single dimension ndarray
- Group dataframe and get sum AND count?
- Sample each group after pandas groupby
- Pandas groupby with categories with redundant nan
- Is there an “ungroup by” operation opposite to .groupby in pandas?
- get first and last values in a groupby
- Pandas groupby and aggregation output should include all the original columns (including the ones not aggregated on)
- Get the row corresponding to the max in pandas GroupBy [duplicate]
- How to get number of groups in a groupby object in pandas?
- Aggregation in Pandas
- Pandas groupby mean – into a dataframe?
- How to drop duplicates based on two or more subsets criteria in Pandas data-frame
- Make Pandas groupby act similarly to itertools groupby
- Python pandas – filter rows after groupby
- Pandas groupby nlargest sum
- Pandas get frequency of item occurrences in a column as percentage [duplicate]
- group by week in pandas
- Pandas groupby to to_csv
- Pandas groupby with bin counts
- Pandas groupby and qcut
- how to convert monthly data to quarterly in pandas