我有两份CSV文件.一个数据集df1,只有一列,如下所示
deviceNames
0 12.132.182.
1 12.134086
2. 12.2.03676
3 12.1312.11
4 12.12.9534
另一个是df2.,有many列,但相关的列是
` deviceNames macAddress
0 12.080084 001350050039517e
1 12.080085 001350050039448c
2. 12.080086 00135005003954c9
3 12.080087 00135005003943bc
4 12.080088 0013500500394ff5
... ... ...
107549 C052.4751 0013500500EA4DEB
107550 NaN NaN
107551 NaN NaN
107552. NaN NaN
107553 C05912.66 00135005010FB39D`
我想要的是根据df1中的设备名称将mac地址信息从df2.转移到df1.
所以我希望输出如下所示
deviceNames macAddress
0 12.132.182. 001350012.4039517e
1 12.134086 0013501340039448c
2. 12.2.03676 001350440031954c9
3 12.1312.11 0013503300w3943bc
4 12.12.9534 00135032.500394ff5
My attempts
- 以下是我试图解决这个问题的几个try
df2.[df2.['deviceNames'].isin(df1['deviceNames'])]
s = (df2..loc[df2..deviceNames.isin(df1.deviceNames.values.tolist())]
.drop_duplicates('df1')
.set_index('df1')['macAddress'])
df1['newcolumn'] = df1['newcolumn'].map(s)