Using Python3 Convert Csv File Xlsx File Q37102905

Using python3,
how do i convert a csv file to an xlsx file?


Solution


CodeToCopy:

Note:

For installing pandas module, use this command in linux

$ sudo pip3 install pandas

csv_to_xlsx.py

# importing pandas module as pd

import pandas as pd

import sys

numArgs = len(sys.argv)

# checking number of command line arguments

# 1st argument — input file path

# 2nd argument — optional output file path; by default outputfile will be ‘output.xlsx’

# 3rd argument — delimiter between two fields; by defualtcomma(,) will be a delimiter

if numArgs is 1 or numArgs > 4:

    print(“Usage: ” + sys.argv[0] + ” <inputcsv file> [output xlsx file path] [field_delimiter]”)

    exit(1)

# initializing variables with default

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.