简体   繁体   中英

merge multiple data frames (more than 2) in Python

My source data is a list of data frames as below:

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  ]

I would like to merge as runing below codes, however the output is not a data frame but the attributes of object, I am still fresh with Python. Somebody shade me a light? Thanks lot.

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)

Solved

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM