将多个csv读取到pandas中的多个数据帧中

将多个csv读取到pandas中的多个数据帧中

问题描述:

是否可以通过循环将多个csv文件读入Pandas并进行定义?

Is there a way to read multiple csv files into 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))

我看到有关将多个csv读取并附加到单个数据帧中的多个问题.并非如此.

I see multiple questions about reading and appending multiple csvs into a single dataframe. Not the other way around.

您可以将dict comprehension用于DataFramesdict:

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

print (dfs['a'])