Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas groupby size column name

import pandas as pd

df = pd.DataFrame({'A': ['x', 'x', 'x','y','y']
                , 'B': ['a', 'c', 'c','b','b']})
print (df)
   A  B
0  x  a
1  x  c
2  x  c
3  y  b
4  y  b

df = df.groupby(['A', 'B']).size().reset_index(name='Size')
print (df)
   A  B  Size
0  x  a     1
1  x  c     2
2  y  b     2
Comment

PREVIOUS NEXT
Code Example
Python :: Tkinter canvas draggable 
Python :: making variable if it is none python 
Python :: pandas concat / merge two dataframe within one dataframe 
Python :: csv reader python skip header 
Python :: print 2d array in python 
Python :: user nextcord interactions 
Python :: python filter 
Python :: pandas read google sheet 
Python :: get file names in folder python 
Python :: how to sort dictionary in python by value 
Python :: Iterate through python string starting at index 
Python :: python difference between consecutive element in list 
Python :: dictionary function fromkeys in python 
Python :: python turtle background image 
Python :: remove emoji from dataframe 
Python :: instagram private account hacking code python 
Python :: how to cancel a input in python 
Python :: django get or 404 
Python :: hotkey python 
Python :: django rest framework default_authentication_classes 
Python :: how to playsound in python 
Python :: pyspark datetime add hours 
Python :: python oprators 
Python :: all files in directory python 
Python :: tuple with one element python 
Python :: swapping array location in python 
Python :: create a role with discord.py 
Python :: im save to a bytes io python 
Python :: replace a string in a list 
Python :: Flatten List in Python Using List Comprehension 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =