熊猫 - 将多个 Excel 文件读取到单个熊猫数据帧中



我正在尝试将多个 excel 文件读入 Pandas 数据帧。

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

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_)

当我打开数据帧 csv 文件时,我看到单个文件的全部内容都在一行中。我正在尝试在文件输出中的单独行中说源文件中的每一行。

与其根据列表创建pd.DataFrame,不如使用pd.concat将它们连接起来,即

file = pd.concat(list_)

最新更新