python在循环中创建dataframe(如df1、df2……)

需要循环读取文件夹中的csv,创建dataframe

使用exec函数

rootPath=""
excelNames = os.listdir(rootPath)
for i in range(len(excelNames)):
    csvpath=rootPath+"\\"+excelNames[i]    
    exec('df{0} = pd.read_csv(csvpath)'.format(i))

你可能感兴趣的:(python)