【问题标题】:Analysing Time Series in Python - pandas formatting error - statsmodels在 Python 中分析时间序列 - pandas 格式错误 - statsmodels
【发布时间】:2016-03-24 09:08:15
【问题描述】:

我正在尝试分析星星的数据。我有星星的光时间序列,我想预测它们属于哪个类别(在 4 种不同类型中)。 我有这些恒星的光时间序列,我想通过去季节化、频率分析和其他可能相关的研究来分析这些时间序列。

对象time_series是一个panda DataFrame,包括10列:time_points_b、light_points_b(b代表蓝色)等...

我首先想研究蓝光时间序列。

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'

【问题讨论】:

    标签: python numpy pandas statsmodels


    【解决方案1】:

    seasonal_decompose() 期望在您的 DataFrame 上有一个 DateTimeIndex。这是一个例子:

    【讨论】:

    • 这个“seasonal_decompose”函数的文档在哪里?你怎么知道它需要一个 DateTimeIndex?我试图在网上找到它,但不能,只有很小的使用示例。我想看看这个函数期望/产生的输入和输出。谢谢!
    • 您可以从函数的文档字符串中获得基本的使用方法(有几种方法可以做到这一点,但一种方法是print sm.tsa.seasonal_decompose.__doc__)。至于 DateTimeIndex,我必须从 'Int64Index' object has no attribute 'inferred_freq' 错误中拼凑起来。快速谷歌搜索发现它是 pandas 的 DateTimeIndex 的一部分,所以试了一下,它就成功了。
    猜你喜欢
    • 2017-01-09
    • 1970-01-01
    • 2016-10-26
    • 2014-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多