使用数据透视表重新组织时间序列数据

时间:2019-11-02 16:00:05

标签: pivot-table

我有许多加密货币的时间序列数据,如下所示。 BTC出现ETH等之后(日期不匹配,即时间序列的长度不同)

enter image description here

我现在想要的是将符号变为列,因此第一列应为BTC,第二列应为ETH ...,并且条目变为收盘价(“ close”)。我尝试了以下代码:

table = table.pivot_table(columns='symbol')
# By specifying col[1] in below list comprehension
# You can select the stock names under multi-level column
table.columns = [col[1] for col in table.columns]
table.head()

但这会产生以下错误:TypeError:“ int”对象不可下标。

我确信必须有一个容易解决问题的方法。

如果我使用以下内容:

表= table.pivot(索引='日期',列='符号',值='关闭')

我收到另一条错误消息:ValueError:索引包含重复的条目,无法重塑。

尽管整个想法是要有重复项并将其分组...

0 个答案:

没有答案