![]() |
Help in pandas group by - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Help in pandas group by (/thread-24531.html) |
Help in pandas group by - prakash8813 - Feb-18-2020 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 |