Using Python/Pandas to extract data associated with each of the cities and save in separate excel sheet using loop or function
I think this is what you want -
import pandas as pd
df = pd.DataFrame(data)
workbook = pd.ExcelWriter("City Data.xlsx", engine="xlsxwriter")
for city, city_data in df.groupby("city"):
city_data.to_excel(workbook, sheet_name=city)
workbook.save()
The output looks like -
The data are in separate sheets of the Excel workbook as required.