142k views
1 vote
Using a third-party package of your choice, write a program that reads the contents of a csv file and saves it to an Excel file. The program should take two arguments. The name of the input file and the name of the output file.

User Grayasm
by
5.3k points

1 Answer

0 votes

Answer:

import pandas as pd

df = pd.read_csv("file_csv")

df.to_excel("file.xlsx", sheet_name = "name_of_sheet")

# or use: with df.ExcelWriter("file.xlsx", mode='a') as file,

#df.to_excel(file, sheet_name= "sheet name")

Step-by-step explanation:

This python source code uses the pandas package to read csv (comma separated values) file and converts it to an excel file (xlsx) using the read_csv and ExcelWriter methods respectively.

User Pravin Bansal
by
5.9k points