I want to create a pandas dataframe using the two list of dictionaries below:
country_codes = [
{
"id": 92,
"name": "93",
"position": 1,
"description": "Afghanistan"
},
{
"id": 93,
"name": "355",
"position": 2,
"description": "Albania"
},
{
"id": 94,
"name": "213",
"position": 3,
"description": "Algeria"
},
{
"id": 95,
"name": "1-684",
"position": 4,
"description": "American Samoa"
}
]
gender = [
{
"id": 1,
"name": "Female"
},
{
"id": 3
"name": "Male"
}
]
The dataframe should have two columns: Gender
and Country Code
. The values for gender will be from the gender variable while the value for country code will be from the country code variable.
I have tried:
df = pd.DataFrame(list(
zip(
gender,
country_codes
)
),
columns=[
"name"
"description"
]
).rename({
"name": "Gender",
"description": "Country"
}))
writer = pd.ExcelWriter('my_excel_file.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name="sample_sheet", index=False)
writer.save()
But after running the script, the excel file was not populated.
The expected output is have the excel sheet (screenshot attached) populated with the data in those list of dictionaries I declared above