Program to convert Excel file into csv

Python Small Project for Practice

Program to convert Excel file into csv

Project Description

You are a business analyst and you receive every day an Excel file of product sales (sales.xlsx) like the following:

IDproductcategorypricefinal_priceorigin_countrycurrencydiscunt
A1TVelectronics500.0600GermanyUSDyes
A2phoneelectronics175.0210ChinaUSDno
A3laptopelectronics450.0540TaiwanUSDyes
A4screenelectronicsNaNNaNunknownUSDno

Everyday you have to do the same boring task: Open the excel, select the “ID”, “final_price” and “currency” columns, delete the headers and save it as a csv with the “|” as separator so you can load it manually in the operations application of the company. You are tired of this job, so the aim of this Python small project for practice is to automate the conversion of the Excel into a “csv”.

Your task is to write a script that reads the excel in the downloads folder, and export it to the desktop as a csv file. The “csv” must have no headers, the mentioned columns, no index and the pipeline as separator.

It is a real task, many professionals have to carry out on a daily basis to update or process business data in the systems. You will practice the core concepts of the Pandas library to import/export datasets.

Source code

## We import pandas
import pandas as pd

## We read the spreadsheet

retail_prices = pd.read_excel('C:\Dowloads\sales.xlsx')

### We export as csv
retail_prices.to_csv('C:\User\Desktop\sales.csv',sep='|',headers=False,
names = [ "ID", "final_price","currency"],index=False)

To improve your data wrangling skill, see other real python projects for data analysis.

 

We will be happy to hear your thoughts

Leave a reply

Python and Excel Projects for practice
Register New Account
Shopping cart