0 %
!
Programmer
SEO-optimizer
English
German
Russian
HTML
CSS
WordPress
Python
C#
  • Bootstrap, Materialize
  • GIT knowledge
0

No products in the cart.

Convert csv to excel

10.02.2025

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.

How to convert csv file to excel format very easily

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!

Posted in Portfolio, PythonTags:
Write a comment
© 2025... All Rights Reserved.