Skip to content

Instantly share code, notes, and snippets.

@davidandrzej
Created October 25, 2012 23:30
Show Gist options
  • Select an option

  • Save davidandrzej/3956125 to your computer and use it in GitHub Desktop.

Select an option

Save davidandrzej/3956125 to your computer and use it in GitHub Desktop.
"vertically" concat a bunch of csv files in Pandas
from pandas import *
import dateutil
import os, os.path
csvdir = os.getcwd()
filenames = [os.path.join(csvdir,csvfile)
for csvfile in os.listdir(csvdir)
if csvfile[-4:] == '.csv']
dfs = [io.parsers.read_csv(filename,
converters={0:dateutil.parser.parse})
for filename in filenames]
for (df,name) in zip(dfs, filenames):
df.columns = ['date','value_of_interest']
df['filename'] = name
df = concat(dfs, ignore_index=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment