问题标签 [json-normalize]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - 使用 pd.json_normalize 展平字典
我目前正在拼合这个字典文件,并且已经遇到了一些障碍。我正在尝试使用json_normalize
扁平化这些数据。如果我使用单个实例进行测试,它可以工作,但如果我想展平所有数据,它将返回一个错误,指出key error '0'
我不确定如何解决这个问题。
数据示例——
我的代码
python-3.x - 使用 json_normalize 从嵌套值构建表
我在使用 json_normalize 时遇到了麻烦,因为 record_path 指向一个列,其中有一个嵌套的 dict 然后包含一个列表。例如,请参见下文。
鉴于以下情况:
我可以使用
获得以下内容:
如果 list_of_dict 的结构如下,我如何获得类似的输出格式:** 注意 STUDENT_LIST 的添加**
python-3.x - 使用 pandas.json_normalize 时保护嵌套对象不被展平
在 pandas >= 1.1.4 / Python 3 中,我想在使用json_normalize()时保护嵌套元素不被展平。
我无法在文档中弄清楚这样的事情。
实际示例
这是一个具体的例子来弄清楚主要思想:
这是来自 API 响应的单个 JSON 记录。在这里,顶级列表中只有一个元素,但可能还有更多,每个元素都遵循与此处所示相同的结构。我想将它导入到没有包含结构化元素的列的DataFrame中,即我想将它们全部展平/规范化。嗯,……几乎所有。json_normalize()
在这方面做得非常出色:
以下是 DataFrame 的列:
通缉行为
但是我需要,让我们说,“保护”geometry
输入 JSON 响应中的对象不被展平,以便我最终得到这些列:
这将导致:
有没有办法正确地做到这一点?
python-3.x - nested dictionary in list to dataframe python
Have a json input from api:
have initially run
then ran the json_normalize method:
Here is the initial output where the stock_data is still contained within a list. stock_data ISIN update_datetime 0 [{'description': 'zzz', 'industry': 'C', 'ticker... xxx time
stock_data | ISIN | update_datetime | |
---|---|---|---|
0 | [{'description': 'zzz', 'industry': 'C', 'ticker...] | 123 | time |
What i would like to achieve is a dataframe showing the headers and the corresponding rows:
description | industry | ticker | ISIN | update_datetime | |
---|---|---|---|---|---|
0 | 'zzz' | 'C' | xxx | 123 | time |
Do direct me if there is already an existing question answered :) cheers.
python - 缺少键时使用 json_normalize 函数
我遇到了该json_normalize
功能的问题。指定项目可能缺少的键时,会引发键错误。如您所见,listPeople
文件中并不总是存在。
根据文档,使用errors = "ignore"
应该可以解决问题,但这似乎不起作用?
预期输出:
python - 从列标题中删除整数列表键
我有一个 Python 脚本,它使用了以前 Stack Overflow解决方案中的一个函数。
电流输出:
我遇到的问题是列名中包含的数字键。有没有办法可以修改我的代码以实现我想要的输出?
期望的输出:
python - Json_normalise 从嵌套 API 到 DF 抛出类型错误
我正在尝试使用具有以下结构的 api 并将其加载到 pandas DF 中,每个项目 ID 有一行,例如 2、6 和每个条目的高、高、低和低列。
到目前为止,我一直在 json_normalise 上使用 json_normalise 响应,它为每个条目加载一行,其中包含多个嵌套列:
结果,我尝试为“数据”添加record_path,认为这可以解决它是嵌套列表的事实,但这样做会抛出
我认为那是因为我的 res['data'] 类型是一个字典,而不是它本身的列表,但我有点困惑如何解决这个问题,或者这是否正确。
任何帮助将不胜感激
python - python - 如何使用Python列出JSON非列表项以及带有pandas.json_normalize的列表项?
使用这个 JSON 对象,我想使用 pandas.json_normalize 对其进行规范化。
当我这样做时:
我fields
以这样的表格形式列出了列表:
id field_type tooltip_text name_plural name_singular backref_name backref_tooltip_text allow_multiple allowed_otypes options builtin_name
(后跟数据行)
但我也是外部属性, id
,title
并builtin_name
与字段一起列出
所以我结束了这个:
id builtin_name 标题 id field_type tooltip_text name_plural name_singular backref_name backref_tooltip_text allow_multiple allowed_otypes options builtin_name
我试过这个:
但它会抛出一个错误,说 id 不是列表。
也尝试不使用方括号无济于事。
如何让这些字段"id", "builtin_name", "title"
与每行中的其他字段一起列出?
谢谢!