create new column in dataframe using fuzzywuzzy

前端 未结 1 1235
迷失自我
迷失自我 2021-01-18 23:58

I have a dataframe in pandas where I am using fuzzywuzzy package in python to match first column in the dataframe with second column.

I hav

相关标签:
1条回答
  • 2021-01-19 00:18

    You're passed a Series to work with inside the apply function, representing the current row here. In your code, you're effectively ignoring this Series and trying to call partial_ratio with the two whole columns of the DataFrame each time (driver[col]).

    A minor change to your code should hopefully give you what you want.

    d = DataFrame({'one': ['fuzz', 'wuzz'], 'two': ['fizz', 'woo']})
    
    d.apply(lambda s: fuzz.partial_ratio(s['one'], s['two']), axis=1)
    
    0    75
    1    33
    dtype: int64
    

    (Interestingly, the partial_ratio function will accept a Series as input, but only because it converts it internally into a string. :)

    0 讨论(0)
提交回复
热议问题