From the course: Python Functions for Data Science

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Group data from pandas objects

Group data from pandas objects - Python Tutorial

From the course: Python Functions for Data Science

Start my 1-month free trial

Group data from pandas objects

- [Instructor] When working with pandas objects you'll find yourself needing to group your data in a certain manner. I'll be walking through a couple of examples to demonstrate how to group data using pandas functions. Let's say that I have a variable named grades containing a Panda state of frame, and the data frame consists of students scores across five exams. I've displayed it here. Now say I want to group the grade state of frame by the student ID column in order to calculate the mean grade for each student ID. I can use the pandas group by function for grouping and the pandas mean function for calculating the means. I want to get a new Panda's data frame that contains student ID as the index and a grade column that holds the mean grade for each student ID. First, I'll call the drop function and set the keyword argument columns to exam to drop the exam column. Since I don't need the exam numbers in the results.…

Contents