如何重新采样时间序列 Pandas 数据框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21408264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resample a time series Pandas dataframe?
提问by Hugo
I am trying to resample 1 minute based data to day. I have tried the following code on IPython
我正在尝试重新采样基于 1 分钟的数据。我在 IPython 上尝试了以下代码
import pandas as pd
import numpy as np
from pandas import Series, DataFrame, Panel
import matplotlib.pyplot as plt
%matplotlib inline
data = pd.read_csv("DATALOG_22_01_2014.csv",\
names = ['DATE','TIME','HUM1','TMP1','HUM2','TMP2','HUM3','TMP3','WS','WD'])
data.set_index(['DATE','TIME'])
data.resample('D',how=mean)
But I got the following error
但我收到以下错误
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-75-aa63b6b16877> in <module>()
----> 1 data.resample('D', how=mean)
NameError: name 'mean' is not defined
Could you help me?
你可以帮帮我吗?
Thank you
谢谢
Hugo
雨果
回答by DSM
Try
尝试
data.resample('D', how='mean')
instead. Right now you're asking Python to pass the meanobject to the resamplemethod as the howargument, but you don't have one defined.
反而。现在你要求 Python 将mean对象resample作为how参数传递给方法,但你没有定义一个。

