This may be a duplicate please let me know.
I have a pandas df like this:
| id | name | Common |
|---|---|---|
| One | A | |
| One | A | |
| One | A | |
| One | B | |
| Two | C |
I'd like to output something like this:
Where the most common name for each id is placed in the common column.
| id | name | Common |
|---|---|---|
| One | A | A |
| One | A | A |
| One | A | A |
| One | B | A |
| Two | C | C |
I've tried this but at this point i'm throwing darts in the dark
df.groupby(['id', 'name']).agg(lambda x:x.value_counts().index[0])
df.groupby(['id'])['name'].transform(lambda x: x.value_counts().index[0])or usex.mode()[0]inside.