0
      A    B
0   Red  3.9
1   Red  4.1
2   Red  2.3
3  Blue -1.2
4  Blue -9.2
5  Blue -6.1

I want to create a new df['C'] with maximum B value, per each A group.

Output should be:

      A    B    C
0   Red  3.9  4.1
1   Red  4.1  4.1
2   Red  2.3  4.1
3  Blue -1.2 -1.2
4  Blue -9.2 -1.2
5  Blue -6.1 -1.2

I´ve tried:

df['C'] = df.groupby('A')['B'].max()
taras
  • 6,566
  • 10
  • 39
  • 50
Tie_24
  • 625
  • 4
  • 14
  • Doesn't look like a basic python question? Are you using a third party library? If so I would suggest you to add that information and also add a tag. – noorul Aug 03 '18 at 14:52
  • I guess he wants to map out the max values by the groups as a new column but the duplicate doesnt answer that fully. you can try this `max = df.groupby('A')['B'].max().reset_index()` `max.columns =['A', 'C']` `df1 = pd.merge(df, max, on='A')` – Zmnako Awrahman Aug 03 '18 at 15:00
  • No need to merge. Just use transform as indicated in the duplicate. – ALollz Aug 03 '18 at 15:15

0 Answers0