两个数据框:df1,df2。如果df2.index中的df1.index,则df1 ['mask'] = 1,否则df ['mask'] = 0

时间:2019-07-30 11:31:32

标签: pandas

两个数据帧:df1df2

  

如果df2.index中的df1.index,则df1 ['mask'] = 1,否则df ['mask'] = 0

df3是预期的结果。

import pandas as pd
data1 = {'key':['a','b','c','d','e','f','g'], 'profit':[12,3,4,5,6,7,9]}
df1 = pd.DataFrame(data1)
data2= {'key':['a','b','c'], 'profit':[12,3,4]}
df2 = pd.DataFrame(data2)
data3 = {'key':['a','b','c','d','e','f','g'], 'profit':[12,3,4,5,6,7,9],
'mask':[1,1,1,0,0,0,0]}
df3=pd.DataFrame(data3)

0 个答案:

没有答案