У меня есть несколько списков dict, которые сходятся к одному списку dict в файл excel.Идея состоит в том, чтобы сделать лист Excel для каждого слова, ключа (web1, web2), имени и иметь правильную информацию на каждом листе.Проблема кода ниже состоит в том, что он создает файл Excel из одного листа.Есть идеи, как мне это сделать?
import pandas as pd
web1 = [{
'country': 'NL',
'id': '56655',
'title': 'some 1',
'date': 'today',
'description': 'something else here',
'web': 'http://'
},
{
'country': 'IE',
'jobid': '45862',
'title': 'some 2',
'date': 'today',
'description': 'something else here',
'web': 'http://'
}]
web2 = [{
'country': 'IT',
'id': '77878',
'title': 'some 3',
'date': 'today',
'description': 'something else here',
'web': 'http://'
},
{
'country': 'NE',
'id': '45862',
'title': 'some 4',
'date': 'today',
'description': 'something else here',
'web': 'http://'
}]
data =[{
'website1': web1
},
{
'website1': web2
}]
for x in data:
z = str(*x).capitalize()
for y in x.values():
cx = pd.DataFrame(y, columns = ['country', 'title', 'date', 'id', 'web','description'])
writer = pd.ExcelWriter('test.xlsx')
cx.to_excel(writer, sheet_name=f'{z}')
workbook = writer.book
worksheet = writer.sheets[f'{z}']
align_r = workbook.add_format({'align': 'right'})
bold = workbook.add_format({'bold': True})
color_format = workbook.add_format({'bg_color': 'green'})
condi_color = worksheet.conditional_format('G:G', {
'type': 'text',
'criteria': 'containing',
'value': 'red',
'format': color_format})
# set column spacing, format
worksheet.set_column('A:A', 3)
worksheet.set_column('B:B', 2, bold)
worksheet.set_column('C:C', 40, bold)
worksheet.set_column('D:D', 10, align_r)
worksheet.set_column('G:G')
writer.save()