【问题标题】:Downsampling data frome 25hz to 10hz将数据从 25 赫兹降到 10 赫兹
【发布时间】:2021-10-12 22:36:29
【问题描述】:

我有一些以 25hz 采样的时间序列数据(每秒 25 个样本)

time_in_secconds    data_vals
199.655    0.549038
199.696    0.83472
199.736    0.478569
199.776    0.114157
199.817    0.217603
199.858    0.701952
199.898    0.23409
199.938   -0.237923
199.979    0.337316
200.019    1.17735
200.059    1.42538

我想降低到每秒 10 个样本。我一直在考虑用 pandas 来做这件事,并且有几个问题。第一个是我使用什么索引对象?是https://pandas.pydata.org/docs/reference/api/pandas.TimedeltaIndex.seconds.html 吗?

第二个是,在这样做之后,我实际上如何重新采样以在新的 10hz 上同时获得 time_in_secondsdata_vals

【问题讨论】:

    标签: python pandas downsampling


    【解决方案1】:

    resample 函数的文档包含更多有用的信息。

    由于time_in_secods 测量某个事件后的时间,因此TimedeltaIndex 在这里是最合适的。以下是如何通过平均原始数据点来重新采样:

    # Original data @ 25Hz
    t = np.arange(199, 201, .04)
    df = pd.DataFrame({
        'time_in_seconds': t,
        'data_vals': np.random.uniform(-1, 1, len(t))
    })
    
    # Resample to 10Hz
    output = (
        df.set_index(pd.to_timedelta(df['time_in_seconds'], unit='s'))
          ['data_vals']
          .resample('100ms')
          .mean()
    )
    output.index = output.index.total_seconds()
    

    还有其他重采样方法,例如minmax 或加权平均。有关详细信息,请参阅文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      • 1970-01-01
      • 2013-06-20
      • 2014-04-20
      相关资源
      最近更新 更多