Apr-04-2024, 05:38 PM
(This post was last modified: Apr-04-2024, 05:38 PM by deanhystad.)
Please post the entire error message, including the traceback. My guess is that one of the columns contains floats.
This works:
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()