pandas describe of describe

Question:

I have a DataFrame and there are two columns. One of it is the names and another one is some number. I need to count mean of it for every unique name.

Tried .describe(), but it shows only for all DataFrame, not a unique names. If anyone could help, I would be thankful.

Asked By: ddddd

||

Answers:

You can group your data by name and calculate the mean for each group using the ‘groupby’ method in pandas. Here’s an example assuming your DataFrame is called ‘df’ and your columns are called "name" and "number":

grouped = df.groupby('name')
means = grouped['number'].mean()

This will give you a pandas Series object with the mean for each unique name in the "name" column.

Answered By: Ulrich
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.