I have the following dataframe:
COD ACT DATE
0 5713 1.0 2020-07-16
1 5713 1.0 2020-08-11
2 5713 1.0 2020-06-20
3 5713 1.0 2020-06-19
4 5713 1.0 2020-06-01
5 23369 1.0 2020-07-17
6 23369 1.0 2020-08-07
7 23369 1.0 2020-09-02
8 23369 1.0 2020-11-22
9 32012 1.0 2020-06-02
10 32012 1.0 2020-07-26
I want to calculate the mean and standard deviation of each COD on the whole time series. Previously I was calculating like this:
df['MEAN'] = df.groupby("COD")["ACT"].transform("mean")
df['STD'] = df.groupby("COD")["ACT"].transform("std")
But this calculated the mean for the time span of the initial timestamp for ACT and final timestamp for ACT (like 3 ACT within 5 months - not 8 months). ACT is the timestamp for the activity, but the whole timeseries has 8 months. I want to calculate the mean and standard deviation for the whole 8 months. Can anyone help me?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.