【发布时间】:2015-03-25 20:37:40
【问题描述】:
当从 dict 构造数据帧时,以下示例会抛出 IndexError(index out of bounds)。
import pandas as pd
d = {(0,1):{1:'a'}}
pd.DataFrame.from_dict(d,orient='index')
如果我修改dict如下,没有索引错误
import pandas as pd
d = {1:{1:'a'}}
pd.DataFrame.from_dict(d,orient='index')
为什么元组作为dict键会导致IndexError?
【问题讨论】:
-
第一个 ex 在 v0.15.1 上按预期工作
-
我使用的是 0.14.1。是时候更新了!你能发布一个答案吗?我会接受的。
-
欢迎接受 unutbu 的一个。无论如何,她/他比我更博学。
标签: python dictionary pandas