pandas 模糊合并两个dataframe

import pandas as pd
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
inp = [{'c1':10, 'ID':"CMCC_VOLTE_Ainter_15.8"}, {'c1':11,'ID':"CMCC_VOLTE_Ainter_15.9"}, {'c1':12,'ID':"CMCC_VOLTE_Ainter_15.7"}]
df1 = pd.DataFrame(inp)
df["id_split"] = df["ID"].apply(lambda x: x.split('_'))
df
inp1 = [{'c1':10, 'ID':"[CMCC][VOLTE]{[Ater][15.8][mbj][99]"}, {'c1':10, 'ID':"[CMCC][VOLTE]{[Ater][15.811111][mbj][99]"},{'c1':11,'ID':"[CMCC][VOLTE][p][p][p][Ater][iiii][15.7]"}, {'c1':12,'ID':"[CMCC][0000][VOLTE][Ainter][15.9]"}]
df= pd.DataFrame(inp1)
df1
df1['key']=df1.ID.apply(lambda x : [process.extract(x, df.ID, limit=1)][0][0][0])
df1
df1.merge(df,left_on='key',right_on='ID')

ID_x	c1_x	key	ID_y	c1_y

0 CMCC_VOLTE_Ainter_15.8 10 [CMCC][VOLTE]{[Ater][15.8][mbj][99] [CMCC][VOLTE]{[Ater][15.8][mbj][99] 10
1 CMCC_VOLTE_Ainter_15.9 11 [CMCC][0000][VOLTE][Ainter][15.9] [CMCC][0000][VOLTE][Ainter][15.9] 12
2 CMCC_VOLTE_Ainter_15.7 12 [CMCC][VOLTE][p][p][p][Ater][iiii][15.7] [CMCC][VOLTE][p][p][p][Ater][iiii][15.7] 11

上一篇:查看电脑上连接过的WiFi密码


下一篇:Hadoop基础---流量求和MapReduce程序及自定义数据类型