Python Forum
Help in pandas group by
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help in pandas group by
#1
I have below dataframe:-
df=pd.DataFrame({'a':[1,1,1,1,2,2,2,2],'b':[1,1,2,2,2,6,7,7]})
a b
1 1
1 1
1 2
1 2
2 2
2 6
2 7
2 7

I want to create a new column called say "cnt", so that it gives count of unique b for same a. For ex:- in above case "cnt" would be like

a b cnt
1 1 1
1 1 1
1 2 2
1 2 2
2 2 1
2 6 2
2 7 3
2 7 3
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to group variables & check correlation of group variables wrt single variable SriRajesh 2 2,928 May-23-2018, 03:01 PM
Last Post: SriRajesh
  Calculation using group by and pandas sarabi1005 0 2,144 Aug-29-2017, 08:13 PM
Last Post: sarabi1005

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020