how do I convert something like this to a dataframe with pandas?
[{'page': 1, 'pages': 1, 'per_page': '50', 'total': 1},
[{'adminregion': {'id': 'MNA',
'iso2code': 'XQ',
'value': 'Middle East & North Africa (excluding high '
'income)'},
'capitalCity': 'Cairo',
'id': 'EGY',
'incomeLevel': {'id': 'LMC',
'iso2code': 'XN',
'value': 'Lower middle income'},
'iso2Code': 'EG',
'latitude': '30.0982',
'lendingType': {'id': 'IBD', 'iso2code': 'XF', 'value': 'IBRD'},
'longitude': '31.2461',
'name': 'Egypt, Arab Rep.',
'region': {'id': 'MEA',
'iso2code': 'ZQ',
'value': 'Middle East & North Africa'}}]]
CodePudding user response:
The point is how to put each element in a dataFarame. Row-wise:
pd.DataFrame(dic.items(), columns=['Date', 'Value'])
or columns-wise:
pd.DataFrame([dic])
CodePudding user response:
I would suggest a different approach. add the data in a csv file and read that file into a dataFrame.
You could try this if interested:
import pandas as pd
df = pd.read_csv("file path")
then you could see the dataframe output:
print(df.head())