Created
February 24, 2020 16:42
-
-
Save firemonk9/475d343b4113a6273c21c9b22dd11db7 to your computer and use it in GitHub Desktop.
sample python code to convert xlsx to csv files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xlrd | |
import csv | |
import glob | |
import os | |
from os import sys | |
def csv_from_excel(excel_file): | |
workbook = xlrd.open_workbook(excel_file) | |
all_worksheets = workbook.sheet_names() | |
for worksheet_name in all_worksheets: | |
worksheet = workbook.sheet_by_name(worksheet_name) | |
with open(u'{}.csv'.format(worksheet_name), 'wb') as your_csv_file: | |
wr = csv.writer(your_csv_file, quoting=csv.QUOTE_ALL) | |
for rownum in xrange(worksheet.nrows): | |
wr.writerow([unicode(entry).encode("utf-8") for entry in worksheet.row_values(rownum)]) | |
os.rename(your_csv_file.name,excel_file+".csv") | |
v=glob.glob("/hadoop/met_scripts/analytics/model_monitoring/ltd_Fwa_data/*.xlsx") | |
for i in v: | |
print(i) | |
csv_from_excel(i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment