【发布时间】:2021-12-26 06:09:54
【问题描述】:
以下是股票价格数据,我将其保存到 DataFrame 中。 t 列是代表时间的序列号。
| a | b | t |
|---|---|---|
| 1.20 | 5.45 | 1636534800000 |
| 7.98 | 1.33 | 1636542000000 |
| 8.29 | 2.44 | 1636549200000 |
| 8.76 | 6.55 | 1636556400000 |
- 如果我输入 arrow.get(1636534800000),那么我会得到 2021-11-10T09:00:00+00:00 没有问题
但是,执行以下操作时出现错误。注意t列的数据类型是int64
trade_date = df.loc[0,'t']
date_reformat=arrow.get(trading_date)
错误信息:
"raise TypeError(f"Cannot parse single argument of type {type(arg)!r}.") TypeError: Cannot parse single argument of type
."
- 我需要一个代码来将 t 列中的值替换为“实时”而不是序列号。 t 列中的值是 UTC 时区,我住在美国东海岸,所以我需要它来调整回东部时间。但是我们有夏令时。我们目前处于 EST 时区,3 月后我们将前往 EDT 时区。因此,如果时间在 3 月和 11 月之间,则 t 应调整为 UTC-4,其余时间 t 列应调整为 UTC-5。我不需要“+00:00”,我只需要那个 year-month-dateThh:mm:ss
【问题讨论】:
-
不确定它为什么起作用,但是用 int() 包装你的 trade_date。 trade_date = int(df.loc[0,'t']) date_reformat=arrow.get(trade_date)
标签: python pandas date datetime