Convert csv to excel
Sometimes there is no time to open csv files separately and turn them into an easy to view format in Excel. See exactly what delimiters are in the document or change the encoding, etc. It is for these purposes that we have prepared a Python script that will allow you to convert such data easily and simply.
The code is very simple even for beginners: just import the necessary libraries and specify the full path to the .CSV file. Beforehand, of course, set the relative path to the source file so that the final result is saved in the same folder.
csv to excel – easy!
import pandas as pd
import os
# set directory of the project
base_dir = os.path.dirname(__file__)
csv_file = r'C:\DIRECTORY01\your_file_name.csv'
# Create an Excel file name based on a CSV file
excel_file = os.path.splitext(csv_file)[0] + '.xlsx'
# Upload CSV file
data = pd.read_csv(csv_file)
# Save the data in Excel format
data.to_excel(excel_file, index=False) # index=False removes indexes from an Excel file
This way you get a finished .XLSX file from the required .CSV format. This file conversion is much faster than manually opening the file and converting it to the desired format. In addition, you can customize the script to process many similar files in one folder.
Oh, and the file name is taken from the original file, which is very handy when you don’t have time to rename them separately!

Professional data parsing via ZennoPoster, Python, creating browser and keyboard automation scripts. SEO-promotion and website creation: from a business card site to a full-fledged portal.