熊猫-将多个Excel文件读入单个熊猫数据框

时间:2019-12-11 10:05:29

标签: python excel pandas dataframe

我正在尝试将多个Excel文件读入Pandas Dataframe。

我已经准备好了以下代码:

allFiles = glob.glob(base2 + "/*.xls"). <<-- Reading from path where all files are stored
list_ = []
for file_ in allFiles:
    df = pd.read_excel(io.BytesIO(open(file_, 'rb').read()), sheet_name='Sheet1') <<-- using io module to read the file as there are some issue with the text format
    list_.append(df)

print(list_)
file = pd.DataFrame(list_)

当我打开Dataframe csv文件时,我会在单个行中看到单个文件的全部内容。我试图让源文件中的每一行都在文件输出的单独一行中说。

1 个答案:

答案 0 :(得分:1)

而不是根据列表创建pd.DataFrame,而是使用pd.concat将它们串联起来,即

file = pd.concat(list_)