I have a dataframe with a DateTime index:
>>>df.head()
Out:
Conn_ses
DateTime
2018-07-02 14:46:08 332
2018-07-02 15:00:53 328
2018-07-02 15:05:53 324
2018-07-02 15:10:53 326
2018-07-02 15:15:53 326
I now want to select the rows every 30 minutes (so starting from 15.00) So, i tried df.resample
but it gives me the warning that only resample.mean()
or resample.sum()
can be used. However, I don't need that, i want to retain my original values. This is my result when using resample:
>>> df1=df['Conn_ses'].resample('30Min')
>>> df1.head()
/.../W10 data analysis.py:1: FutureWarning: .resample() is now a deferred operation
use .resample(...).mean() instead of .resample(...)
from datetime import datetime
DateTime
2018-07-02 14:30:00 332.000000
2018-07-02 15:00:00 323.333333
2018-07-02 15:30:00 314.000000
2018-07-02 16:00:00 296.666667
2018-07-02 16:30:00 248.833333
Freq: 30T, Name: Conn_ses, dtype: float64
Is the resample method the right one in this case? If not, how can I approach this issue?
I believe you need:
df1 = df['Conn_ses'].resample('30Min').first()
print (df1)
DateTime
2018-07-02 14:30:00 332
2018-07-02 15:00:00 328
Freq: 30T, Name: Conn_ses, dtype: int64
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.