Mike answer above works fine. In case any googler encounters the following error:
>>> TypeError: cannot concatenate object of type "<type 'str'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid
This is possible because the delimiter is not correct. I used a custom CSV file, so the delimiter was ^ . Because of this, I needed to enable the delimiter in the pd.read_csv call.
import os for csv in globbed_files: frame = pd.read_csv(csv, sep='^') frame['filename'] = os.path.basename(csv) data.append(frame)
source share