我们正在尝试将python字典转换为JSON文件。这样做时,我们在下面出现错误。
"TypeError: Object of type 'ndarray' is not JSON serializable"
这里是用于执行此操作的代码
1. Convert Pandas data frame to dictonary
**records = df.to_dict(orient='records')**
2. replace NaN value with none
**for record in records:
print(record)
for key in record:
print(key)
if record[key] != record[key]:
record[key] = None**
3. then save dictionary to json file
**out = '\n'.join([json.dumps(r, allow_nan=True) for r in records])**
在步骤3中,我们遇到了上面提到的错误。
谢谢