我试图根据是否存在郊区匹配将两个数据帧合并在一起,但是我得到了返回给一列的nan值。
Solar['Suburb'] = Solar['Suburb'].astype(str)
Solar['Solar Count'] = Solar['Solar Count'].astype(str)
Prop['T1'] = Prop['T1'].astype(str)
Prop['Property Count'] = Prop['Property Count'].astype(str)
merged = pd.merge(Prop, Solar, left_on = 'T1', right_index=True, how ='right')
merged.reset_index(drop=True)
哪个返回:
['T1'] ['Property Count'] ['Suburb'] ['Solar Count']
ACACIA RIDGE NaN ACACIA RIDGE 760
ADARE NaN ADARE 156
ADVANCETOWN NaN ADVANCETOWN 83
ALBANY CREEK NaN ALBANY CREEK 2322
ALBERTON NaN ALBERTON 76
ALBION NaN ALBION 133
但是希望得到:
ACACIA RIDGE 1111 ACACIA RIDGE 760
ADARE 23231 ADARE 156
ADVANCETOWN 100 ADVANCETOWN 83
ALBANY CREEK 5000 ALBANY CREEK 2322
ALBERTON 80 ALBERTON 76
ALBION 300 ALBION 133
我知道这是返回Nan的原因,因为左侧与右侧不匹配,但是可以解决这个问题吗? 谢谢