Python:JSON规范化“字符串索引必须为整数”错误

Sheema Murugesh巴布

我在以下代码中收到“ TypeError:字符串索引必须为整数”的类型错误。

import pandas as pd 
import json
from pandas.io.json import json_normalize

full_json_df = pd.read_json('data/world_bank_projects.json')
json_nor = json_normalize(full_json_df, 'mjtheme_namecode')
json_nor.groupby('name')['code'].count().sort_values(ascending=False).head(10)
Output:
TypeError                                 
Traceback (most recent call last)
<ipython-input-28-9401e8bf5427> in <module>()
      1 # Find the top 10 major project themes (using column 'mjtheme_namecode')
      2 
----> 3 json_nor = json_normalize(full_json_df, 'mjtheme_namecode')
      4 #json_nor.groupby('name')['code'].count().sort_values(ascending = False).head(10)
TypeError: string indices must be integers
学生

根据pandas文档data该方法的参数为json_normalize

data:字典或字典列表未序列化的JSON对象

在上面,pd.read_json返回dataframe所以,你可以尝试转换dataframedictionary使用.to_dict()也有多种使用to_dict()的选项

可能如下所示:

json_normalize(full_json_df.to_dict(), ......)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

JSON字符串索引必须为整数

Django序列化器从帖子访问json数据(字符串索引必须为整数)

类型错误:字符串索引必须是带 JSON 的整数

JSON 注释错误“字符串索引必须是整数”

处理使用'http'下载的JSON时发生错误-TypeError:字符串索引必须为整数

类型错误:字符串索引必须是整数(Python)

Python引发错误-字符串索引必须是整数

Python 错误字符串索引必须是整数

错误:字符串索引必须是整数

TypeError字符串索引必须为整数-python json dict

解析JSON时,字符串索引必须为整数-python

字符串索引必须是整数json python

Python - 读取 JSON - TypeError:字符串索引必须是整数

如何“规范化” Python 3 Unicode字符串

python规范化修复字符串

TypeError:使用Python解析Json时,字符串索引必须是整数错误

python pandas - 解析 JSON 时出现类型错误:字符串索引必须是整数

类型错误:在 Python 中过滤 JSON 中的值时,字符串索引必须是整数

Javascript 规范化字符串

从字符串中提取某些整数,然后对其进行规范化

如何解决“ TypeError:字符串索引必须为整数”错误?

为什么会出现错误“ TypeError:字符串索引必须为整数”

异常值:字符串索引必须为整数:渲染包错误vue + django

如何解决错误字符串索引在文本扩展中必须为整数

熊猫数据框-字符串索引必须为整数-

openpyxl TypeError:字符串索引必须为整数

TypeError:字符串索引必须为整数

Flask 中的“类型错误:字符串索引必须是整数”

/ 字符串索引处的类型错误必须是整数