Python convert extracted excel file to csv

+1 vote

Need help in Python code. My requirement is to extract all the excel files from source folder, convert to csv, move these csv files to target folder and delete all excel files in source folder. I tried the following command but it just converts the excel files to csv. 

import glob 
path_to_excel_files = glob.glob('path/to/excel/files/*.xlsx')
for excel in path_to_excel_files:
 out = excel.split('.')[0]+'.csv'
 df = pd.read_excel(excel)
 df.to_csv(out) 
Feb 8, 2019 in Python by Jishan
6,497 views

2 answers to this question.

+1 vote

Try the following script:

import pandas as pd
import os
import glob


source="D:\\source\\"
dest='D:\\dest\\'
os.chdir(source)

for file in glob.glob("*.xls"):
       df = pd.read_excel(file)
       df.to_csv(dest+file+'.csv', index=False)
       os.remove(file)
for file in glob.glob("*.xlsx"):
       df = pd.read_excel(file)
       df.to_csv(dest+file+'.csv', index=False)
       os.remove(file)
answered Feb 8, 2019 by Omkar
• 69,210 points
+1 vote
Some services require table data in CSV format. If you have information in Excel files, it is easy to export it to CSV format using this free online Excel converter. It produces converted copies similar to desktop Total Excel Converter, but does not require installation and license registration.

This is an excellent solution for one-time quick conversion, when there is no time to install software on the computer and no need to do that often. When you convert Excel to CSV online, you will not be offered to set any options, and this saves your time significantly.
answered Aug 30, 2019 by Mian Tanzeel
Is there an API that I can use with Python?

Related Questions In Python

0 votes
1 answer

Python convert all sheets of excel to csv

You will have to parse through the ...READ MORE

answered Feb 9, 2019 in Python by Omkar
• 69,210 points
6,911 views
+1 vote
4 answers

Python: convert txt file to csv format with rows and columns

Python will read data from a text ...READ MORE

answered Dec 14, 2020 in Python by Gitika
• 65,910 points
56,463 views
0 votes
2 answers

How do I convert text file to CSV file with only plain python. Meaning no panda or any other special module?

Steps to Convert Text File to CSV ...READ MORE

answered Oct 15, 2020 in Python by Abdul Shekh
8,264 views
0 votes
1 answer

How to read Excel File in Python

With pandas it is possible to get ...READ MORE

answered Oct 22, 2018 in Python by Priyaj
• 58,090 points
1,548 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,411 views
–1 vote
1 answer

Python convert excel file to csv

Here you go: import glob path_to_excel_files = glob.glob('path/to/excel/files/*.xlsx') for ...READ MORE

answered Feb 8, 2019 in Python by Omkar
• 69,210 points
961 views
+1 vote
2 answers

Python convert XLS and XLSX file to csv

XLSX tables are usually created in MS ...READ MORE

answered Aug 30, 2019 in Python by Mian Tanzeel
17,203 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP