Friday, 13 May 2022

excel to csv in python

 import pandas as pd,xlrd,glob

excel_files = glob.glob(r"D:\python\python_*.xlsx")

for excel_file in excel_files:

 print("Converting '{}'".format(excel_file))

  try:

      df = pd.read_excel(excel_file)

      output = excel_file.split('.')[0]+'.csv'

      df.to_csv(output,index=False)

  except KeyError:

      print(" Failed to convert")


No comments:

Post a Comment