【发布时间】:2020-07-07 17:24:54
【问题描述】:
更新:我正在使用“Socrata Open Source API”中的一些示例代码。我注意到代码中的以下注释:
# First 2000 results, returned as JSON from API / converted to Python
# list of dictionaries by sodapy.
我不熟悉 JSON。
我已经下载了一个数据集,创建了一个包含大量列的 DataFrame 'df'。
df = pd.DataFrame.from_records(results)
当我尝试使用 describe() 方法时,我得到“TypeError: unhashable type: 'dict'”:
df.describe()
...
TypeError: unhashable type: 'dict'
如何识别产生此错误的列?
更新 2: 根据 Yuca 的要求,我附上了 df 的摘录:
【问题讨论】:
-
你能把
df.head()的结果包括进来吗? -
如果您只是想找出哪些列产生了错误,您可以使用
for column in df然后使用df[column].describe(),因为列只是系列,您可以在系列上调用 describe -
@Yuca - 列太多,无法包含 head 的输出。你在找什么?
-
@Thunderwood - 抱歉,我在 Juypter Notebook 中执行此操作。当我接受你的建议时,没有输出。帮忙?
-
数据框构造函数的结果。
describe是内置的,所以它失败的唯一原因是有一个扭曲的 DataFrame
标签: python json pandas socrata