我是熊猫库的初学者,我有以下数据集作为JSON文件:
array(
[
{'paragraphs':
[
{'qas':
[
{'question': "Quel astronome a émit l'idée en premier d'une planète entre les orbites de Mars et Jupiter ?",
'id': '9f38825f-1bd3-4171-9d3b-b0c2c71e7de2',
'answers': [
{'text': 'Johann Elert Bode', 'answer_start': 136}
]
},
{'question': 'Quel astronome découvrit Uranus ?',
'id': 'c2415641-9a62-4052-b57b-9a239da7599c',
'answers': [
{'text': 'William Herschel', 'answer_start': 404}
]
},
{'question': 'Quelles furent les découvertes finales des vingt-quatre astronomes ?',
'id': '5c59e19a-066c-4dc0-aa16-2871dcb12d39',
'answers': [
{'text': 'plusieurs autres astéroïdes', 'answer_start': 733}
]
}
],
'context': "L'idée selon laquelle une planète inconnue pourrait..."
}
]
}
]
)
我想要一个脚本来从这个JSON文件中提取问题、文本和上下文。 我尝试了以下脚本:
import pandas as pd
df = pd.read_json('train.json', orient='columns')
print(df.head()['data'])
我得到的结果是:
0 {'paragraphs': [{'qas': [{'question': "Quel as...
1 {'paragraphs': [{'qas': [{'question': 'America...
2 {'paragraphs': [{'qas': [{'question': "A quell...
3 {'paragraphs': [{'qas': [{'question': "Pourquo...
4 {'paragraphs': [{'qas': [{'question': "Quels s...
jmespath在这里可能会有所帮助,因为它允许轻松遍历嵌套的json数据:
相关问题 更多 >
编程相关推荐