在Python中合并多个数据帧(超过2个)

时间:2013-12-01 06:15:07

标签: python merge pandas append

我的源数据是一个数据框列表,如下所示:

In [101]: res
Out[101]: 
[  Round              Date               Home     Score             Away  
0     1  15/08/2009 20:45         Chelsea FC  2-1(1-1)        Hull City  
1     1  15/08/2009 23:00   Blackburn Rovers  0-2(0-1)  Manchester City  
2     1  15/08/2009 23:00             Wolves  0-2(0-1)  West Ham United  
3     1  15/08/2009 23:00   Bolton Wanderers  0-1(0-1)       Sunderland  
4     1  15/08/2009 23:00         Stoke City  2-0(2-0)          Burnley  
5     1  15/08/2009 23:00         Portsmouth  0-1(0-1)           Fulham  
6     1  15/08/2009 23:00        Aston Villa  0-2(0-1)   Wigan Athletic  
7     1  16/08/2009 01:30            Everton  1-6(0-3)          Arsenal  
8     1  16/08/2009 21:30  Manchester United  1-0(1-0)       Birmingham  
9     1  17/08/2009 00:00  Tottenham Hotspur  2-1(1-0)        Liverpool  ,
   Round              Date             Home     Score               Away  
0     2  19/08/2009 03:45       Sunderland  1-3(1-0)         Chelsea FC  
1     2  19/08/2009 03:45   Wigan Athletic  0-1(0-1)             Wolves  
2     2  20/08/2009 03:45          Burnley  1-0(1-0)  Manchester United  
3     2  20/08/2009 03:45        Hull City  1-5(1-3)  Tottenham Hotspur  
4     2  20/08/2009 03:45       Birmingham  1-0(0-0)         Portsmouth  
5     2  20/08/2009 04:00        Liverpool  4-0(2-0)         Stoke City  
6     2  05/11/2009 04:45  West Ham United  2-1(1-0)       Aston Villa   
7     2  26/11/2009 05:00           Fulham  3-0(1-0)   Blackburn Rovers  
8     2  21/01/2010 04:45          Arsenal  4-2(1-2)   Bolton Wanderers  
9     2  25/03/2010 04:45  Manchester City  0-2(0-1)            Everton  ,
   Round              Date             Home     Score               Away  
0     3  22/08/2009 23:00        Hull City  1-0(0-0)   Bolton Wanderers  
1     3  22/08/2009 23:00       Birmingham  0-0(0-0)         Stoke City  
2     3  22/08/2009 23:00       Sunderland  2-1(1-1)   Blackburn Rovers  
3     3  22/08/2009 23:00          Arsenal  4-1(2-1)         Portsmouth  
4     3  22/08/2009 23:00  Manchester City  1-0(1-0)             Wolves  
5     3  22/08/2009 23:00   Wigan Athletic  0-5(0-0)  Manchester United  
6     3  23/08/2009 21:30  West Ham United  1-2(0-0)  Tottenham Hotspur  
7     3  23/08/2009 23:00          Burnley  1-0(1-0)            Everton  
8     3  24/08/2009 00:00           Fulham  0-2(0-1)         Chelsea FC  
9     3  25/08/2009 04:00        Liverpool  1-3(0-2)        Aston Villa  ,
   Round              Date               Home     Score             Away  
0     4  29/08/2009 20:45         Chelsea FC  3-0(1-0)          Burnley  
1     4  29/08/2009 23:00         Stoke City  1-0(1-0)       Sunderland  
2     4  29/08/2009 23:00   Blackburn Rovers  0-0(0-0)  West Ham United  
3     4  29/08/2009 23:00             Wolves  1-1(0-1)        Hull City  
4     4  29/08/2009 23:00  Tottenham Hotspur  2-1(0-0)       Birmingham  
5     4  29/08/2009 23:00   Bolton Wanderers  2-3(1-1)        Liverpool  
6     4  30/08/2009 01:15  Manchester United  2-1(0-1)          Arsenal  
7     4  30/08/2009 21:30         Portsmouth  0-1(0-1)  Manchester City  
8     4  30/08/2009 23:00            Everton  2-1(0-0)   Wigan Athletic  
9     4  31/08/2009 00:00        Aston Villa  2-0(1-0)           Fulham  ]

我想合并为运行下面的代码,但是输出不是数据框,而是对象的属性,我仍然对Python很新鲜。有人给我一个灯光吗?非常感谢。

res2 = res[0]
i = 1
while i < len(res):
     res2 = res2.append(res[i])
     i = i + 1
res2
print res2
Out[102]: 
<class 'pandas.core.frame.DataFrame'>
Int64Index: 380 entries, 0 to 9
Data columns (total 6 columns):
Round    380  non-null values
Date     380  non-null values
Home     380  non-null values
Score    380  non-null values
Away     380  non-null values
         380  non-null values
dtypes: object(6)

1 个答案:

答案 0 :(得分:1)

解决

pandas.set_option('display.height', 500)
pandas.set_option('display.max_rows', 500)