【问题标题】:Numpy: Save time series dataNumpy:保存时间序列数据
【发布时间】:2019-11-17 14:49:58
【问题描述】:

下图是 6 个位置网格的时间序列数据示例。

timestamp = "2019-10-01"
temp = np.array([(22.1, 22.2, 22.3), (22.4, 22.5, 22.6)])
rh = np.array([(50.1, 50.2, 50.3), (50.4, 50.5, 50.6)])

可以使用np.savez() 将其保存到文件中以供以后分析。用 CSV 术语思考,目标是在单个文件中包含多个这样的 "2019-10-01", "2019-10-02" 等)。那么问题来了,如何存储 Numpy 数组时序数据呢?

【问题讨论】:

  • 看这个:tpcg.io/PwMp8Aa1
  • 谢谢,这让我得到了一个日期数组。关键是,时间戳(日期)数组的形状为 (X),而其余数据变量的形状为 (X, 2, 3),其中 X 是测量次数。
  • x = timestamp 用作x.month, x.year and x.day
  • 你这是什么意思?
  • 只需将时间转换为date =np.array([(x.month, x.year , x.day)])

标签: numpy time-series


【解决方案1】:

最好将日期存储为年、月和日以匹配您的数据集。当您需要将其恢复到最新状态时,请使用join

import numpy as np 
from numpy import savetxt
import sys
import pandas as pd
timestamp = "2019-10-01"
year ,month,day = timestamp.split('-')

date =np.array([( year ,month, day)])
temp = np.array([(22.1, 22.2, 22.3), (22.4, 22.5, 22.6)])
rh = np.array([(50.1, 50.2, 50.3), (50.4, 50.5, 50.6)])
a=date.astype(str)

for row  in a:
    x='-'.join(row) 
print(x)

查看代码here

【讨论】:

    猜你喜欢
    • 2012-03-11
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    • 2020-11-02
    • 1970-01-01
    • 2014-08-03
    • 2019-02-08
    相关资源
    最近更新 更多