Read multiple csvs on multiple data frames in Pandas

Is there a way to read multiple csv files in Pandas through a loop and define them as such?

for i in ['a', 'b', 'c', 'd']:
    csv_(i) = pd.read_csv('C:/test_{}.csv'.format(i))

I see several questions about reading and adding multiple csvs to one data frame. Not the other way around.

+4
source share
1 answer

You can use dict comprehensionfor dictto DataFrames:

dfs = {i: pd.read_csv('C:/test_{}.csv'.format(i)) for i in ['a', 'b', 'c', 'd']}

print (dfs['a'])
+6
source

Source: https://habr.com/ru/post/1672851/


All Articles