Skip to content

Instantly share code, notes, and snippets.

@wh1t3h47
Last active October 2, 2024 04:05
Show Gist options
  • Save wh1t3h47/a1571d4ea96f37713e036a3b02509f47 to your computer and use it in GitHub Desktop.
Save wh1t3h47/a1571d4ea96f37713e036a3b02509f47 to your computer and use it in GitHub Desktop.
Convert all excel in ./ to csv
from os import listdir
import pandas as pd
for f in listdir():
if f.endswith('xlsx'):
df = pd.DataFrame(pd.read_excel(f))
csv_f = f[:-4:] + 'csv'
df.to_csv(csv_f, index=None, header=True)
continue
# this one is to combine all csv into one and drop duplicates, writes one single csv as combined.csv in ./
all_dataframes = []
for f in listdir():
if f.endswith('csv'):
df = pd.read_csv(f)
all_dataframes.append(df)
combined_df = pd.concat(all_dataframes).drop_duplicates()
combined_df.to_csv('combined.csv', index=None, header=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment