【问题标题】:selecting specific rows based on timestamp in pandas根据熊猫中的时间戳选择特定行
【发布时间】:2018-03-07 10:47:44
【问题描述】:

我有一个带有 DateTime 索引的数据框:

>>>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

我现在想每 30 分钟选择一次行(所以从 15.00 开始) 所以,我尝试了df.resample,但它警告我只能使用resample.mean()resample.sum()。但是,我不需要那个,我想保留我的原始价值观。这是我使用重采样时的结果:

>>> 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

在这种情况下,重采样方法是否正确?如果没有,我该如何解决这个问题?

【问题讨论】:

  • 您需要df['Conn_ses'].resample('30Min').first() 吗?

标签: python pandas dataframe timestamp


【解决方案1】:

我相信你需要:

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

【讨论】:

    猜你喜欢
    • 2018-05-20
    • 2015-06-20
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多