applying read_csv to a Series of filenames only loads the first dataframe

43 Views Asked by At

When I run this block of code:

import pandas as pd
import os

working_dir = os.getcwd()+'/'
files = pd.Series(os.listdir(working_dir))

input_files = files[files.str.contains('.csv')]
input_files = working_dir+input_files

dataframes = input_files.apply(pd.read_csv)

It returns a series of the same dataframe, the first one I found.

What the? I have confirmed that all the files have different columns and data in them.

I expect that it returns a Series containing a dataframe for every filename in the original Series that the read_csv had been applied to.

1

There are 1 best solutions below

0
Miko On

My bad. The print statement was repeating the same data frame for some reason. I got it working now. Thanks everyone for your input.