Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
149 views
in Technique[技术] by (71.8m points)

python - Combining 2 Dataframes into 1 excel workbook with 2 sheets

I am using the current code to source coronavirus cases and sort into 1 excel workbook with 2 sheets. The code runs without error, but I have no idea where it is? Where would I put my location within my files to get the workbook added to a certain file?

For example, I want the file to be dropped into the file DocumentsCoronavirus.

import pandas as pd

url_cases = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv'
url_deaths = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv'
df_cases = pd.read_csv(url_cases)
df_deaths = pd.read_csv(url_deaths)

writer = pd.ExcelWriter('Daily Coronavirus Data.xlsx', engine='xlsxwriter')

df_cases.to_excel(writer, sheet_name='Sheet1')
df_deaths.to_excel(writer, sheet_name='Sheet1')

writer.save()

Many thanks in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)

It will save in the current directory where you are running the code. I have just changed the name of the file while saving. Run it once and check

import pandas as pd

url_cases = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv' 
url_deaths = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv' 

df_cases = pd.read_csv(url_cases) 
df_deaths = pd.read_csv(url_deaths)

writer = pd.ExcelWriter('Daily_Coronavirus_Data.xlsx', engine='xlsxwriter')

df_cases.to_excel(writer, sheet_name='Sheet1') 
df_deaths.to_excel(writer, sheet_name='Sheet1')

writer.save()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...