我在目录下有几个Excel工作表(使用pd.read_excel
),我想将它们作为大熊猫阅读并将它们添加到列表中。所以我的列表应该最终包含多个数据框。我该怎么办?
答案 0 :(得分:0)
这就是我要怎么做。
import pandas as pd
import glob
# your path to folder containing excel files
datapath = "\\Users\\path\\to\\your\\file\\"
# set all .xls files in your folder to list
allfiles = glob.glob(datapath + "*.xls")
# for loop to aquire all excel files in folder
for excelfiles in allfiles:
raw_excel = pd.read_excel(excelfiles)
# place dataframe into list
list1 = [raw_excel]
答案 1 :(得分:0)
我的方法:
data = os.listdir('data')
df = pd.DataFrame()
for file in data:
path = 'data' + '/' + file
temp = pd.read_excel(path)
df = df.append(temp, ignore_index = True)