Python for循环中的数据帧串联返回空数据帧

Python for循环中的数据帧串联返回空数据帧,python,pandas,stack,append,concat,Python,Pandas,Stack,Append,Concat,我试图将一个数据帧的几个循环数据元素堆叠在彼此之上,以更改数据帧的维度。例如,从100x20到500x4 Sample 11x7 input: 0 1 2 3 4 5 6 7 0 1 713 1622 658 1658 620 1734 1 2 714 1623 657 1700 618 1735 2 3 714 1624 656 1701 617 1736

我试图将一个数据帧的几个循环数据元素堆叠在彼此之上,以更改数据帧的维度。例如,从100x20到500x4

Sample 11x7 input:
    0   1   2   3   4   5   6   7       
0   1   713 1622    658 1658    620 1734        
1   2   714 1623    657 1700    618 1735    
2   3   714 1624    656 1701    617 1736    
3   4   714 1625    655 1702    615 1738    
4   5   714 1626    654 1703    614 1739    
5   6   713 1627    653 1705    612 1740    
6   7   713 1628    651 1706    610 1741    
7   8   713 1629    650 1707    609 1742    
8   9   713 1630    649 1709    607 1744    
9   10  713 1631    648 1710    605 1745    
10  11  712 1632    646 1711    604 1746    

Desired 32x3 output:
0   1   713 1622    
1   2   714 1623    
2   3   714 1624    
3   4   714 1625    
4   5   714 1626    
5   6   713 1627    
6   7   713 1628    
7   8   713 1629    
8   9   713 1630    
9   10  713 1631    
10  11  712 1632    
11  1   658 1658    
12  2   657 1700    
13  3   656 1701    
14  4   655 1702    
15  5   654 1703    
16  6   653 1705    
17  7   651 1706    
18  8   650 1707    
19  9   649 1709    
20  10  648 1710    
21  11  646 1711    
22  1   620 1734        
23  2   618 1735    
24  3   617 1736    
25  4   615 1738    
26  5   614 1739    
27  6   612 1740    
28  7   610 1741    
29  8   609 1742    
30  9   607 1744    
31  10  605 1745    
32  11  604 1746
我花了太多的时间检查这个,我找不到比这个更好的了

pd.concat([df1, df2], ignore_index=True) 
or 
df1.append(df2, ignore_index=True)
,在这种情况下,应产生相同的解决方案。但是,无论使用哪种选项,它都将被放置在循环的末尾,该循环生成要与永久数据帧连接或附加到永久数据帧的临时数据帧。temp df的结果很好,但据称直接的连接步骤始终失败。我得到一个空的数据帧,有一个合适的头


for l in range(1,13):
    s1 = l * 4 - 4
    s2 = l * 4 
    dft = df0.iloc[:, s1:s2]
    dft.columns = new_col
    #pd.concat([df1, dft], ignore_index=True, axis = 0)
    #df1.append(dft, ignore_index=True)
df1.head()

注释掉的任何一行都应该生成一个4宽的临时数据帧堆栈。。。我得到一个空的数据帧,有一个正确的标题,没有错误消息…

由@Aryerez在上面的评论中解决:
默认情况下,pd.concat()和df.append()都不在适当的位置。看看df1=pd.concat(等)是否解决了这个问题

由@Aryerez在上面的评论中解决:
默认情况下,pd.concat()和df.append()都不在适当的位置。看看df1=pd.concat(等)是否解决了这个问题

请提供一些示例输入和所需输出:也许10x2和5x4数据?默认情况下,pd.concat()和df.append()都不存在。看看是否
df1=pd.concat(等…)
解决了它。也许可以重命名columns@Aryerez非常感谢。问题已解决。请提供一些示例输入和所需输出:可能是10x2和5x4数据?默认情况下,pd.concat()和df.append()都不存在。看看是否
df1=pd.concat(等…)
解决了它。也许可以重命名columns@Aryerez非常感谢。问题解决了。