Reza
Reza

Reputation: 728

how to calculate mean of some rows for each given date in a dataframe

I have a dataframe with 5 columns and 50k rows.all columns are int except the date that is date time.

enter image description here

In this dataframe, data gathered for 1 year and there are multiple data for one day. i want to calculate the mean and variance of some columns for each day and put it in a new data frame.

Is there any pandas function or other way to do this?

Upvotes: 0

Views: 1472

Answers (1)

Steven G
Steven G

Reputation: 17122

use groupby, it will return a new dataframe for you.

df.groupby('date').mean()
df.groupby('date').std()

isolating columns:

df.groupby('date')['price_per_unit'].mean()

Upvotes: 4

Related Questions