时间序列重采样错误 - 列 pandas 中没有日期索引 [英] Timeseries resample error - none of Dateindex in column pandas

查看:43
本文介绍了时间序列重采样错误 - 列 pandas 中没有日期索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请原谅明显的错误 - 仍在学习过程中.

Please excuse obvious errors - still in the learning process.

我正在尝试以 15 分钟的频率对我的数据绘制一个简单的时间序列图.这个想法是绘制每月平均值,从每小时重新采样数据开始 - 仅包括那些在间隔中至少有 1 个观察值的每小时平均值.日均值和月均值有后续条件.

I am trying to do a simple timeseries plot on my data with a frequency of 15 minutes. The idea is to plot monthly means, starting with resampling data every hour - including only those hourly means that have atleast 1 observation in the interval. There are subsequent conditions for daily and monthly means.

只有当这个错误没有出现时,这才相对简单 - [DatetimeIndex(['2016-01-01 05:00:00', '2016-01-01 05:15:00',\n....2016-12-31 16:15:00'],\n dtype='datetime64[ns]', length=103458, freq=None)] 在 [columns]"

This is relatively simpler only if this error does not crop up- "None of [DatetimeIndex(['2016-01-01 05:00:00', '2016-01-01 05:15:00',\n....2016-12-31 16:15:00'],\n dtype='datetime64[ns]', length=103458, freq=None)] are in the [columns]"

这是我的代码:

#Original dataframe



      Date   value
0          1/1/2016 0:00  405.22
1          1/1/2016 0:15  418.56
Date     object
value    object
dtype: object


#Conversion of 'value' column to numeric/float values.

df.Date = pd.to_datetime(df.Date,errors='coerce')
year=df.Date.dt.year
df['Year'] = df['Date'].map(lambda x: x.year )

df.value = pd.to_numeric(df.value,errors='coerce' )

Date     datetime64[ns]
value           float64
Year              int64
dtype: object
                      Date   value  Year
0      2016-01-01 00:00:00  405.22  2016
1      2016-01-01 00:15:00  418.56  2016


df=df.set_index(Date)
diurnal1 = df[df['Date']].resample('h').mean().count()>=2
**(line of error)**

diurnal_mean_1 = diurnal1.mean()[diurnal1.count() >= 1]
(the code follows)

对解决错误的任何帮助将不胜感激.

Any help in solving the error will be appreciated.

推荐答案

我想你想要 df=df.set_index('Date')(日期是一个字符串).如果可能的话,我也会将转换转移到构造函数中.

I think you want df=df.set_index('Date') (Date is a string). Also I would move the conversions over into the constructor if possible after you get it working.

这篇关于时间序列重采样错误 - 列 pandas 中没有日期索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆