我在JSON文件中有一个字典,我已经将该JSON文件加载到我的MySQL Notebook中。
- 第一个键是stats键,它是关于字典的基本统计信息
- 第二个关键是命名问题,它是关于调查中提出的问题
- 第三个关键是答案,即问题的答案。
我的问题是我已经将JSON文件转换为DataFrame,但所有问题的列名都不是干净的形式。My DataFrame Columns
我想要干净的问题。
import numpy as np
import pandas as pd
import json
# Load Json File
filepath = "C:/Users/osmi-survey-2016_1479139902.json"
with open(filepath,"r") as openFile:
my_json_file_health = json.load(openFile)
# Extract questions and responses
questions = my_json_file_health.get("questions", [])
responses = my_json_file_health.get("responses", [])
# Create a list of dictionaries for responses with column names as keys
response_dicts = [{question["question"]: response["answers"].get(question["id"], None) for question in questions}
for response in responses]
# Convert the list of response dictionaries to a DataFrame
responses_df = pd.DataFrame(response_dicts)
responses_df
字符串
1条答案
按热度按时间gcmastyq1#
给您:
字符串