Template request | Bug report | Generate Data Product
Tags: #python #csv #excel #pandas #file
Author: Sophia Iroegbu
Description: This notebook provides a step-by-step guide to converting CSV files to Excel spreadsheets using Python.
import pandas as pd
# Declare the absolute path to the CSV file
csv_input = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
# Name the XSLX spreasheet needed as an output
excel_output = "covid_dataset.xlsx"
- read the CSV file link,
- then convert it to Excel spreadsheet file by using the
to_excel
function.
The sep
argument helps to seperate the rows. It might be a ,
or a ;
and also, ensure the CSV link ends with a CSV file extension.
convert_csv = pd.read_csv(csv_input, sep=",")
convert_csv
The header=True
ensures the header from CSV file is converted. This saves the .xlsx file on your root directory.
convert_csv.to_excel(excel_output, index=False, header=True)