
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:
| ID | product | category | price | final_price | origin_country | currency | discunt |
|---|---|---|---|---|---|---|---|
| A1 | TV | electronics | 500.0 | 600 | Germany | USD | yes |
| A2 | phone | electronics | 175.0 | 210 | China | USD | no |
| A3 | laptop | electronics | 450.0 | 540 | Taiwan | USD | yes |
| A4 | screen | electronics | NaN | NaN | unknown | USD | no |
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.