Skip to content

Latest commit

 

History

History
52 lines (31 loc) · 2.03 KB

Python_Convert_CSV_to_Excel.md

File metadata and controls

52 lines (31 loc) · 2.03 KB



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.

Input

Import library

import pandas as pd

Variables

# 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"

Model

Use pandas to:

  • 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

Output

Save result in .xlsx file

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)