[英]how do merge two dataframe in pandas
我想合並兩個基於數據框的第一列。 這是其他建議的代碼:
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)
這是我在上面的代碼中遇到的錯誤:
/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)
如何合並以第一列為索引的df1和df2
從有關如何合並的文檔中,它看起來很簡單:
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)
left
是df1
,右邊是df2
, on
是第一列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.