Skip to content

Instantly share code, notes, and snippets.

@saburbutt
Last active June 23, 2020 02:42
Show Gist options
  • Save saburbutt/50a545d2529a41361ac7f18e3ddcf6eb to your computer and use it in GitHub Desktop.
Save saburbutt/50a545d2529a41361ac7f18e3ddcf6eb to your computer and use it in GitHub Desktop.
Reading multiple csv files and storing the data in the pandas dataframe
import pandas as pd
from pathlib import Path
from glob import glob
allfiles = sorted(glob('Files/yob*.csv'))
print(allfiles)
home = str(Path.home())
#The * in the path is basically the variable which changes in every file
#Read the full data and concatenate all the csv files
full_data = pd.concat((pd.read_csv(file) for file in allfiles), ignore_index = True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment