【问题标题】:ValueError: could not convert string to float: '01-01-20 0:15'ValueError:无法将字符串转换为浮点数:'01-01-20 0:15'
【发布时间】:2020-12-28 06:47:34
【问题描述】:

下面是我正在处理的示例数据集,我每 30 分钟存储一次平均值。

|Slot              |    value|
|01-01-2018 00:30  |   78.3  |
|01-01-2018 01:00  |   74.5  |
|01-01-2018 01:30  |   79.2  |
|01-01-2018 02:00  |   78.7  |
|01-01-2018 02:30  |   77.3  |
|01-01-2018 03:30  |   76.4  |

当我尝试为此数据集绘制自相关函数 (ACF) 图时,我收到错误消息:

ValueError:无法将字符串转换为浮点数:'01-01-20 0:15'

这是我的代码

from statsmodels.graphics.tsaplots import plot_acf
plot_acf(freq)

【问题讨论】:

  • 在绘图前将slot设置为DataFrame索引,df.set_index('Slot',inplace=True)

标签: python arima autocorrelation


【解决方案1】:

plot_acf 函数接受值,滞后需要在单独的参数中定义。

plot_acf(df['value'])

如果延迟对您很重要(我认为它不重要,因为您已经有固定的 30 分钟间隔),您可以定义延迟。

lags = [0, 30, 60, 90...]
plot_acf(df['value'], lags=lags)

https://www.statsmodels.org/stable/generated/statsmodels.graphics.tsaplots.plot_acf.html

【讨论】:

    猜你喜欢
    • 2021-02-14
    • 2020-02-11
    • 1970-01-01
    • 1970-01-01
    • 2022-08-04
    • 2019-03-23
    • 2018-06-13
    • 2013-05-30
    • 1970-01-01
    相关资源
    最近更新 更多