2014-05-22 4 views
0

두 개의 데이터 프레임을 기반으로하는 첫 번째 열을 병합하고 싶습니다. 여기 팬더에서 두 개의 데이터 프레임을 병합하는 방법

import pandas as pd 

movie_genres =[[u'Drama', u'Romance', u'Sci-Fi'], 
[u'Biography', u'Drama', u'History', u'War'], 
[u'Animation', u'Adventure', u'Family', u'Fantasy'], 
[u'Biography', u'Drama', u'History', u'War']] 

movie_id = [u'0338013', 
u'0363163', 
u'0347149', 
u'0395169'] 

movie_year = [u'(2004)', 
u'(2004)', 
u'(2004)', 
u'(2004)'] 


df1 = pd.DataFrame(pd.Series(movie_genres, movie_id)) 
df2 = pd.DataFrame(pd.Series(movie_year, movie_id)) 


merge(df1, df2, how='left', on=None, left_on=None, right_on=None, 
     left_index=False, right_index=False, sort=True, 
     suffixes=('_x', '_y'), copy=True) 

내가 위의 코드로지고있어 오류입니다 : 여기 는 서로 제안과 코드 인덱스로 첫 번째 열을 가진 DF1 및 DF2를 병합하는 방법

/home/tets/code/viz/testing-dataframe.py in <module>() 
    23 merge(df1, df2, how='left', on=None, left_on=None, right_on=None, 
    24  left_index=False, right_index=False, sort=True, 
---> 25  suffixes=('_x', '_y'), copy=True) 

+1

시도한 방법을 나열 할 수도 있습니까? – fixxxer

+0

http://pandas.pydata.org/pandas-docs/stable/merging.html 또는 google'pandas merge'를 참조하십시오. – joris

답변

1

설명서의 내용은 merge이며 간단합니다.

merge(left, right, how='left', on=None, left_on=None, right_on=None, 
     left_index=False, right_index=False, sort=True, 
     suffixes=('_x', '_y'), copy=True) 

여기서 leftdf1이고 오른쪽은 df2이고 on은 첫 번째 열입니다.

+0

위의 방법으로 http://pastebin.com/sV2ypMVN이 오류가 발생했습니다. – sb32134

관련 문제