Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python中附加数据帧_Python_Python 3.x_Pandas_Loops_Append - Fatal编程技术网

在Python中附加数据帧

在Python中附加数据帧,python,python-3.x,pandas,loops,append,Python,Python 3.x,Pandas,Loops,Append,我有多张在列标题中相同但在行数上不同的表。我想把这些纸合并成一张母版纸 目前,这是我得到的代码,其输出为空,结果是数据=与最后一页中的数据一致 我决定使用遍历data\u sheetnames的for循环,这是一个列表 下面是我使用的代码 combineddata = pd.DataFrame() for club in data_sheetnames: data = pd.read_excel(r'''C:\Users\me\Desktop\Data.xlsx''', header =

我有多张在列标题中相同但在行数上不同的表。我想把这些纸合并成一张母版纸

目前,这是我得到的代码,其输出为空,结果是
数据
=与最后一页中的数据一致

我决定使用遍历
data\u sheetnames
的for循环,这是一个列表

下面是我使用的代码

combineddata = pd.DataFrame()
for club in data_sheetnames:
    data = pd.read_excel(r'''C:\Users\me\Desktop\Data.xlsx''', header = 1, index_col = 2, sheet_name = club)
    combineddata.append(data)

如果我将combineddata更改为空列表,那么我会得到一个数据帧字典。

解决方案是append不能正常工作。 它返回附加的数据帧。 所以

combineddata = pd.DataFrame()
for club in data_sheetnames:
    data = pd.read_excel(r'''C:\Users\me\Desktop\Data.xlsx''', header = 1, index_col = 2, sheet_name = club)
    combineddata = combineddata.append(data)

应该解决这个问题

一个更简单的方法就是这样做:

combined_data = pd.concat([pd.read_excel(sheet_name) for sheet_name in data_sheetnames])

可能重复的感谢,这已经解决了问题。我只能在5分钟内接受。