2

I used groupby to generete the following pd.DataFrame:

                       Timestemp  Altitude [m]  Sequence ID  Horizontal Wind Speed [m/s]  ...  Radial Wind Speed [m/s]  CNR [dB]  U-Component of Wind Speed  V-Component of Wind Speed 
0    2019-07-29 00:00:40.901           100       617375                       7.2750  ...                   -0.006   -15.706                   7.241811                  -0.694118
1    2019-07-29 00:00:40.901           150       617375                       8.0700  ...                    0.252   -14.960                   8.068156                  -0.172526
2    2019-07-29 00:00:40.901           200       617375                       9.6750  ...                    0.572   -13.872                   9.672698                  -0.211059
3    2019-07-29 00:00:40.901           250       617375                       9.7975  ...                    0.424   -12.584                   9.786624                   0.461525
4    2019-07-29 00:00:40.901           300       617375                       9.0325  ...                    0.054   -10.998                   9.029804                  -0.220684
...                      ...           ...          ...                          ...  ...                      ...       ...                        ...                        ...
1612 2019-07-29 00:16:59.713          1500       617425                          NaN  ...                      NaN       NaN                        NaN                        NaN
1613 2019-07-29 00:16:59.713          1550       617425                          NaN  ...                      NaN       NaN                        NaN                        NaN
1614 2019-07-29 00:16:59.713          1600       617425                          NaN  ...                      NaN       NaN                        NaN                        NaN
1615 2019-07-29 00:16:59.713          1650       617425                          NaN  ...                      NaN       NaN                        NaN                        NaN
1616 2019-07-29 00:16:59.713          1700       617425                          NaN  ...                      NaN       NaN                        NaN                        NaN

But now it is a little bit tricky. I want to calculate the mean and std for every 5 min over every single height. so Timestemp with the Altititude over 5 min.

How i can fix that? Did anyone has an idea? Thanks

Carlos
  • 5,991
  • 6
  • 43
  • 82
S.Kociok
  • 168
  • 1
  • 14

2 Answers2

1

You can use resample to group the dataframe by 5 minutes bins. First you need to have your timestamp variable as index and then apply the resample function. "T" stands for minutes. You can find all the codelist here: pandas resample documentation

df.set_index('Timestamp', inplace=True)
df.resample("5T").mean()
df.resample("5T").std()

EDIT: If you want to group also by "Altitude". Remember you still need to have the timestamp on the index.

df.groupby([pd.Grouper(freq="5Min"), "Altitude"]).mean()

df.groupby([pd.Grouper(freq="5Min"), "Altitude"]).std()
0

First you need to set your time column as index. Then you can use the sampling frequency to calculate the mean and standard deviation

df = df.set_index(pd.DatetimeIndex(df['Timestemp']))

dfmean = df.groupby(pd.Grouper(freq='5T')).mean()  # 5min
dfstd = df.groupby(pd.Grouper(freq='5T')).std()
drops
  • 1,524
  • 1
  • 11
  • 20
  • Same here. The altitutde is now also in the mean. A want a five min mean for every hight... so mean over 5 min for all 100m, 200m... heights – S.Kociok Aug 12 '20 at 06:40