Last active
April 2, 2022 18:58
-
-
Save cobanov/bbf90e8dcc8a5c21a80a83edeaf3b320 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 os | |
import pandas as pd | |
all_files = os.listdir() | |
csv_files = [i for i in all_files if i.endswith(".csv")] | |
print(f'Found {len(csv_files)} files.') | |
def merge_csv_files(csv_files): | |
df = pd.DataFrame() | |
for count, csv in enumerate(csv_files): | |
file = pd.read_csv(csv) | |
file["index"] = count | |
df = df.append(file, ignore_index=True) | |
print( | |
f"{count} / {len(csv_files)}", | |
"completed!", | |
round(count / len(csv_files), 2) * 100, | |
"%", | |
) | |
print("Done!", df.shape) | |
return df | |
def save_csv_files(csv_files): | |
df = merge_csv_files(csv_files) | |
print("Saving CSV files...") | |
df.to_csv("merged_csv_files.csv", index=False) | |
def main(): | |
save_csv_files(csv_files) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment