Last active
October 2, 2024 04:05
-
-
Save wh1t3h47/a1571d4ea96f37713e036a3b02509f47 to your computer and use it in GitHub Desktop.
Convert all excel in ./ to csv
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
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