Export worksheets as CSV files using Python

Irakli DD
Jul 15, 2021

--

save excel sheets as csv files, using python (jupyter notebook)

import os
import pandas as pd
from datetime import date

f_name = ‘Samle Data.xlsx’ # Enter excel file name (from the same directory)
prfx = os.path.splitext(f_name)[0] # you can change prefix
sffx = datetime.today().strftime(‘%Y-%m-%d’) # or suffix

WS = pd.ExcelFile(f_name)

for i in range(len(WS.sheet_names)):
df = pd.read_excel(f_name, sheet_name=WS.sheet_names[i], dtype=str)
df.to_csv(prfx + ‘_’ + WS.sheet_names[i] + ‘_’ + sffx + ‘.csv’, sep=’,’, header=True, index=False, encoding=’utf-8')

WS.close()

thats all

--

--

No responses yet