import pandas as pd
deftask1():#********** Begin **********#
data=pd.read_csv('step1/data.csv')
data1=pd.read_csv('step1/data1.csv')
result=pd.concat([data,data1],axis=1)
result=result.T.drop_duplicates().T
result.index.name ='Ladder'
result=result.fillna(0)#********** End **********#return result
第2关:合并与连接
import pandas as pd
deftask2(dataset1,dataset2,dataset3):# ********** Begin **********#
d1,d2,d3=pd.DataFrame(dataset1),pd.DataFrame(dataset2),pd.DataFrame(dataset3)
result=pd.merge(d3,pd.merge(d1,d2,on='user_id',how='outer'),left_on='id',right_on='user_id',how='outer')
result['user_id']=result['user_id'].fillna(result['id'])
result['page_click_count_y']=result['page_click_count_y'].fillna(result['page_click_count_x'])
result['city_x']=result['city_x'].fillna(result['city_y'])
result=result.drop(['id','page_click_count_x','city_y'],axis=1)
result.rename(columns={'city_x':'city','page_click_count_y':'page_click_count'},inplace=True)
result=result.sort_values(by="user_id")
result['user_id']= result['user_id'].values.astype(int)# ********** End **********#return result