在Python中分析时间序列- pandas 格式错误-statsmodels [英] Analysing Time Series in Python - pandas formatting error - statsmodels
问题描述
我正在尝试分析恒星的数据.我有星星的光时间序列,我想预测它们属于哪一类(在4种不同类型中). 我有那些恒星的光时间序列,我想通过进行反季节化,频率分析和其他可能相关的研究来分析这些时间序列.
I am trying to analyse stars' data. I have light time series of the stars and I want to predict to which class (among 4 different types) they belong. I have light time series of those stars, and I want to analyse those time series by doing deseasonalisation, frequencies analysis and other potentially relevant studies.
对象time_series是一个熊猫DataFrame,包括10列:time_points_b,light_points_b(b代表蓝色)等等...
The object time_series is a panda DataFrame, including 10 columns : time_points_b, light_points_b (the b being for blue), etc...
我首先想研究蓝光时间序列.
I first want to study the blue light time series.
import statsmodels.api as sm;
import pandas as pd
import matplotlib.pyplot as plt
pd.options.display.mpl_style = 'default'
%matplotlib inline
def star_key(slab_id, star_id_b):
return str(slab_id) + '_' + str(star_id_b)
raw_time_series = pd.read_csv("data/public/train_varlength_features.csv.gz", index_col=0, compression='gzip')
time_series = raw_time_series.applymap(csv_array_to_float)
time_points = np.array(time_series.loc[star_key(patch_id, star_id_b)]['time_points_b'])
light_points = np.array(time_series.loc[star_key(patch_id, star_id_b)]['light_points_b'])
error_points = np.array(time_series.loc[star_key(patch_id, star_id_b)]['error_points_b'])
light_data = pd.DataFrame({'time':time_points[:], 'light':light_points[:]})
residuals = sm.tsa.seasonal_decompose(light_data);
light_plt = residuals.plot()
light_plt.set_size_inches(10, 5)
light_plt.tight_layout()
当我应用seasonal_decompose方法时,此代码给我一个属性错误: AttributeError:"Int64Index"对象没有属性"inferred_freq"
This code gives me an attribute error when I apply the seasonal_decompose method : AttributeError: 'Int64Index' object has no attribute 'inferred_freq'
推荐答案
seasonal_decompose()
在您的DataFrame上期望DateTimeIndex
.这是一个示例:
seasonal_decompose()
expects a DateTimeIndex
on your DataFrame. Here's an example:
这篇关于在Python中分析时间序列- pandas 格式错误-statsmodels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!