Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas group by multiple columns and count

df.groupby(['col1', 'col2']).size() 
   .sort_values(ascending=False) 
   .reset_index(name='count') 
Comment

PREVIOUS NEXT
Code Example
Python :: Math Module log() Function in python 
Python :: Read XML file to Pandas DataFrame 
Python :: add column in a specific position pandas 
Python :: rename key in dict python 
Python :: how to count unique values in a column dataframe in python 
Python :: python program to add two numbers 
Python :: python permutation 
Python :: difference between 2 timestamps pandas 
Python :: how do i check if a django queryset is empty 
Python :: register model in admin django 
Python :: panda categorical data into numerica 
Python :: model o weight 
Python :: Python Program to Convert Decimal to Binary, Octal and Hexadecimal 
Python :: python open file 
Python :: ParserError: Error tokenizing data. C error: Expected 1 fields in line 6, saw 3 
Python :: creating venv on vscode linux 
Python :: calculating mean for pandas column 
Python :: pandas read first column as index 
Python :: 2 variables with statement python 
Python :: python join with int 
Python :: remove columns from a dataframe python 
Python :: module installed but not found python 
Python :: python change terminal name 
Python :: python divisors 
Python :: modify string in column pandas 
Python :: how to select python 3 interpreter in linux 
Python :: how to close windows in selenium python without quitting the browser 
Python :: python ordered dictionary 
Python :: how to check if a list is a subset of another list 
Python :: how to slice even index value from a list in python using slice function 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =