Python - 用空字典/数组替换空值

标签 python pandas dictionary json-normalize

我想在使用 pandas json_normalize 时用空数组替换 null 值。这是示例:

{
    "id": {
        "0": "x0123455",
        "1": "x0123456"
    },
    "team": {
        "0": null,
        "1": [
            {
                "name": "Jenny",
                "email": "jenny@gmail.com"
            }
        ]
    },

我在某处读到我需要用空字典替换空值以避免出错。我怎样才能做到这一点?

编辑

作为解决方法,我过滤掉了空值

最佳答案

我想你可以做一些简单的事情, 喜欢

for item in items:
    for email in item['team'].values():
        if email == null:
            email = {}

关于Python - 用空字典/数组替换空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70148823/

相关文章:

python - 强制 numpy 保留一个列表

python - 从 List 中查找具有 key 对 'isGeo' :True 的字典

python - 从字典中提取键值对的子集?

python - 外语的词云或可视化

python - 如何为内联有序列表创建正则表达式?

python - 我可以在创建字典时引用字典值吗?

python - 如何在python中的pandas.DataFrame中找出全部用零填充的行或列并将其删除?

python - 从找到的极值中获取完整行数据

c++ - 可能的 : Set Operations on Disparate Maps with Same Key Type?

python - 处理或引发 Python 异常是否有效?