Bottom Page

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
Quote

Top Page

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

Forum Jump:


Users browsing this thread: 1 Guest(s)