Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

pandas-groupby

Groupby value counts on the dataframe pandas

I use groupby and size Timing 1,000,000 rows

Categories Python Tags crosstab, dataframe, pandas, pandas-groupby, python

Count unique values per groups with Pandas [duplicate]

You need nunique: If you need to strip ‘ characters: Or as Jon Clements commented: You can retain the column name like this: The difference is that nunique() returns a Series and agg() returns a DataFrame.

Categories Python Tags group-by, pandas, pandas-groupby, python, unique

Count unique values per groups with Pandas

You need nunique: If you need to strip ‘ characters: Or as Jon Clements commented: You can retain the column name like this: The difference is that nunique() returns a Series and agg() returns a DataFrame.

Categories Python Tags group-by, pandas, pandas-groupby, python, unique

How to groupby based on two columns in pandas?

A similar question might have been asked before, but I couldn’t find the exact one fitting to my problem. I want to group by a dataframe based on two columns. For exmaple to make this Into this: Meaning that summation on “quantity” column for same “id” and same “product”.

Categories Python Tags dataframe, group-by, pandas, pandas-groupby, python

Get statistics for each group (such as count, mean, etc) using pandas GroupBy?

On groupby object, the agg function can take a list to apply several aggregation methods at once. This should give you the result you need:

Categories python Tags dataframe, group-by, pandas, pandas-groupby, python

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress