2013-08-06 11 views

risposta

12

È possibile utilizzare concat:

In [11]: s1 
Out[11]: 
id 
1  3 
3  19 
4  15 
5  5 
6  2 
Name: count_1, dtype: int64 

In [12]: s2 
Out[12]: 
id 
1  3 
3  1 
4  1 
5  2 
6  1 
Name: count_2, dtype: int64 

In [13]: pd.concat([s1, s2], axis=1) 
Out[13]: 
    count_1 count_2 
id 
1   3  3 
3  19  1 
4  15  1 
5   5  2 
6   2  1 

Nota: se questi erano dataframe (invece di serie) si può utilizzare merge:

In [21]: df1 = s1.reset_index() 

In [22]: s1.reset_index() 
Out[22]: 
    id count_1 
0 1  3 
1 3  19 
2 4  15 
3 5  5 
4 6  2 

In [23]: df2 = s2.reset_index() 

In [24]: df1.merge(df2) 
Out[24]: 
    id count_1 count_2 
0 1  3  3 
1 3  19  1 
2 4  15  1 
3 5  5  2 
4 6  2  1 
+0

Grazie per questo - nel tuo primo ad esempio 'id' in col 1, si trova nella riga sotto i titoli 'count_1' e 'count_2' col - per ottenere tutti nella stessa riga, seguo semplicemente il tuo secondo esempio? – user7289

+0

è possibile utilizzare reset_index, che sposta l'indice su una delle colonne. –

+0

@ user7289 cioè 'pd.concat ([s1, s2], asse = 1) .reset_index()' –

Problemi correlati