parse_filename

parse_filename(
    data=None,
    col='file',
    into=None,
    sep='_',
    drop_ext=True,
    remove=False,
)

Split a filename column into metadata columns.

Survey exports often encode metadata in the filename (e.g. “podracing_wave1_NA_2026.csv”). This splits a filename column on a separator into named metadata columns, dropping the file extension first. Pairs naturally with read_folder(), whose file column carries the source filename: split it once and you have event, wave, locale, year, etc. as real columns to group by. The split is on a fixed string (not a regular expression), and rows with fewer fields than into are padded with missing values so a stray filename never derails the parse.

Parameters

Name Type Description Default
data pandas.DataFrame A data frame. If omitted, the session default is used. None
col str The column holding the filename. Default “file”. 'file'
into list of str New column names, one per field you expect after splitting. None
sep str Separator to split on. Default “_“. '_'
drop_ext bool If True (default), strip a trailing file extension before splitting. True
remove bool If True, drop the original filename column. Default False. False

Returns

Name Type Description
pandas.DataFrame The data with the new metadata columns added.

See Also

read_folder

Examples

>>> df = pd.DataFrame({"file": ["podracing_wave1_NA_2026.csv"]})
>>> parse_filename(df, into=["survey", "wave", "locale", "year"])