-1

I have a dataframe with multiple columns i want to compare two columns to each other. I tried to use fuzzywuzzy module than create function and than apply it on column

import pandas as pd
import itertools
import re
import pymorphy2 
import nltk
from nltk.corpus import stopwords 
import difflib
import fuzzywuzzy as fuz
from fuzzywuzzy import fuzz 
from fuzzywuzzy import process

def stringComparison(column1,column2):
score = fuzz.WRatio(column1,column2)
return score

df1['Коэффициент  схожести'] = df1['Условие показа'].apply(stringComparison(df1['Условие показа'], df1['Поисковой запрос']) but i get invalid syntax error 

File "<ipython-input-2-b03e1cc77905>", line 1 df1['Коэффициент схожести']df1['Коэффициент схожести'] = df1['Условие показа'].apply(stringComparison(df1['Условие показа'], df1['Поисковой запрос']) ^ SyntaxError: invalid syntax

What i am doing wrong

Naglyj.Spamer
  • 71
  • 2
  • 9

1 Answers1

0

I am assuming your intention is to apply StringComparison to the columns 'Условие показа' and 'Поисковой запрос' to create 'Коэффициент схожести'

df1['Коэффициент схожести'] = df1.apply(lambda x: stringComparison(x['Поисковой запрос'],x['Условие показа']), axis = 1 )

Your current issues are;

  1. The left hand side of your last line of code is nonsense.
  2. When applied to a series the apply method applies the supplied function to each row of that series. But you only have access to the data contained within that particular series. not any data from other column in the dataframe. In your case it is not using any row information at all and would instead take the whole of df1['Условие показа'] and df1['Поисковой запрос'] as inputs to the stringComparison function.
Ryan
  • 142
  • 6