【发布时间】:2021-06-23 02:30:05
【问题描述】:
我有一个 Python 字典,但是当我尝试将其转储为 JSON 文件时,它说它是 Pandas DataFrame!
import pandas as pd
import os
import re
import json
files_net = [f for f in os.listdir('.') if re.match(r'network_.+.json', f)]
networks = {}
for file in files_net:
with open(file) as f:
networks[re.search(r'network_(.+).json', file).group(1)] = pd.read_json(f)
type(networks)
>>> dict
with open('networks.json', 'w') as f:
json.dump(networks, f)
TypeError: Object of type DataFrame is not JSON serializable
【问题讨论】:
标签: python json pandas dataframe dictionary