Код: Выделить всё
!jupyter nbconvert DataAnalysis.ipynb --no-input --no-prompt --to html
< /code>
Это генерирует HTML -файл, который я должен переименовать, а затем снова изменить переменную «страна» для другой страны, запустите скрипт (кроме последней строки, которая прокомментирована), сохраните результат После отображения графиков и запустить последнюю строку снова и так далее. Страна это) в папке «Отчеты» в цикле попробовала это с помощью CHATGPT, но понятия не имею, что делать: < /p>
import os
# List of countries for which reports are needed
countries = ['Czech Queue','Switzerland Queue','Netherlands Queue','Portugal Queue','Peru Queue','London Queue','Sweden Queue','Slovakia Queue','Finland Queue','Denmark Queue','Norway Queue','Spain Queue','France Queue']
notebook_input = "DataAnalysis.ipynb" # Your original notebook
output_dir = "Reports"
os.makedirs(output_dir, exist_ok=True)
for country in countries:
output_notebook = os.path.join(output_dir, f"{country.replace(' ', '_')}_Report.ipynb")
output_html = os.path.join(output_dir, f"{country.replace(' ', '_')}_Report.html")
print(f"Generating report for {country}...")
# Read the notebook content
with open(notebook_input, "r", encoding="utf-8") as f:
notebook_content = f.read()
# Replace any existing "country =" assignment to the correct country
notebook_content = notebook_content.replace('country = ', f'country = "{country}" #')
# Write the updated notebook
with open(output_notebook, "w", encoding="utf-8") as f:
f.write(notebook_content)
# Execute the notebook in place
os.system(f"jupyter nbconvert --execute --inplace {output_notebook}")
# Convert executed notebook to HTML
os.system(f"jupyter nbconvert {output_notebook} --no-input --no-prompt --to html --output {output_html}")
print("All reports generated successfully!")
Подробнее здесь: https://stackoverflow.com/questions/794 ... results-to