Python Forum
Fuzzy Wuzzy how to get my fuzzyratio displayed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fuzzy Wuzzy how to get my fuzzyratio displayed
#1
Hi, I am a python novice. I am trying to use FuzzyWuzzy to compare the text in 2 columns. I have imported my csv with just the 2 columns I want to compare. I have written this code and it runs:-

def compute_fuzz_ratio():
return fuzz.ratio(['Column1Heading'], ['Column2Heading'])

however when I add df['FuzzRatio'] = df.apply(compute_fuzz_ratio, axis=1) to try and get the ratio displayed in the dataframe I get this error "TypeError: object of type 'float' has no len()" can anyone let me know what I am doing wrong?

Many thanks
Reply
#2
from fuzzywuzzy import fuzz

df['Ratio'] = df.apply(lambda x: fuzz.ratio(x.A, x.B), axis=1)
where A and B are the columns you want to compare.
Reply
#3
Thank you for your response, really appreciated. I've put that code in but I am still getting that same error "TypeError: object of type 'float' has no len()"
Reply
#4
Please post the entire error message, including the traceback. My guess is that one of the columns contains floats.

This works:
from fuzzywuzzy import fuzz
import pandas as pd

df = pd.DataFrame({
    "A": "This is a test".split(), "B": "That was a test".split()
})
df["Ratio"] = df.apply(lambda x: fuzz.ratio(x.A, x.B), axis=1)
print(df)
Output:
A B Ratio 0 This That 50 1 is was 40 2 a a 100 3 test test 100
This fails and gives me the error you are seeing.
from fuzzywuzzy import fuzz
import pandas as pd

df = pd.DataFrame({
    "A": "This is a test".split(), "B": [1.0, 2, 3, 4]
})
df["Ratio"] = df.apply(lambda x: fuzz.ratio(x.A, x.B), axis=1)
print(df)
Error:
TypeError: object of type 'float' has no len()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Table displayed out of order nigelwright7557 3 1,836 Nov-24-2021, 10:07 AM
Last Post: nigelwright7557
  Unexpected output: symbols for derivative not being displayed saucerdesigner 0 2,089 Jun-22-2020, 10:06 PM
Last Post: saucerdesigner
  Auto-copy all displayed "print" results into clipboard? smallabc 1 1,692 Dec-16-2019, 02:10 PM
Last Post: buran
  Percentages displayed as "0.00" Winfried 2 1,825 Nov-15-2019, 05:20 PM
Last Post: Winfried
  implementation fuzzy logic using sckit fuzzy nana_4895 0 2,133 Oct-21-2019, 03:28 AM
Last Post: nana_4895
  Fuzzy match on text columns within dataframe Nsaibot 0 4,345 Aug-27-2018, 10:52 PM
Last Post: Nsaibot
  Exotic stats problem ; mode, fuzzy clusters, etc amyvaulhausen 5 3,943 Aug-06-2018, 04:10 PM
Last Post: Vysero
  Installing fuzzy wuzzy terrancepython11 6 18,338 Mar-25-2017, 06:55 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020