Created
October 25, 2012 23:30
-
-
Save davidandrzej/3956125 to your computer and use it in GitHub Desktop.
"vertically" concat a bunch of csv files in Pandas
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
| 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