By default, columns are all set to zero. Make entry as 1 at (row,column) where column name string present on URL column
L # list that contains column names used to check if found on URL
def generate(statement,col):
if statement.find(col) == -1:
return 0
else:
return 1
for col in L:
df3[col].apply(generate, args=(col))
I am a beginner, it throws and error:
/usr/local/lib/python3.6/dist-packages/pandas/core/series.py in f(x)
4195 4196 def f(x): -> 4197 return func(x, *args, **kwds) 4198 4199 else:TypeError: generate() takes 2 positional arguments but 9 were given
Any suggestions would be helpful
Edit 1:
after,
df3[col].apply(generate, args=(col,))
got error:
> --------------------------------------------------------------------------- AttributeError Traceback (most recent call
> last) <ipython-input-162-508036a6e51f> in <module>()
> 1 for col in L:
> ----> 2 df3[col].apply(generate, args=(col,))
>
> 2 frames pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()
>
> <ipython-input-159-9380ffd36403> in generate(statement, col)
> 1 def generate(statement,col):
> ----> 2 if statement.find(col) == -1:
> 3 return 0
> 4 else:
> 5 return 1
>
> AttributeError: 'int' object has no attribute 'find'
Edit 2: "I missed to emphasize on URL column in for loop code will rectify that"
Edit 3: Updated and fixed to,
def generate(statement,col):
if col in str(statement):
return 1
else:
return 0
for col in L:
df3[col] = df3['url'].apply(generate, col=col)
Thanks for all the support!