You can use pd.concat to concatenate DataFrames. (A join joins DataFrames, and a join joins DataFrames based on common indexes or columns.) When you specify the keys parameter, you get a hierarchical index:
import pandas as pd df = pd.read_csv('GOLD.csv', parse_dates='Date', index_col='Date', sep='\s+') df2 = pd.read_csv('SPX.csv', parse_dates='Date', index_col='Date', sep='\s+') result = pd.concat([df, df2], keys=['GOLD', 'SPX'], names=['ticker']).unstack('ticker') result = result.reorder_levels([1, 0], axis=1).sortlevel(level=0, axis=1) print(result)
gives
ticker GOLD SPX Exp Last Volume Exp Last Volume Date 1978-03-30 198002 995.6 54 198003 215.5 25 1978-03-31 198002 999.5 78 198003 214.1 99
result['Last'] gives a DataFrame:
In [147]: result['Last'] Out[147]: ticker GOLD SPX Date 1978-03-30 995.6 215.5 1978-03-31 999.5 214.1
I would recommend avoiding the syntax result.Last because it is too close to result.Last , which returns the DataFrame method.
To process more files, you can use the following code:
import pandas as pd dfs = list() for filename in filenames: df = pd.read_csv(filename, parse_dates='Date', index_col='Date')
Note that this requires enough memory to store a list of all DataFrames in memory plus enough memory to store result .