0

I have a dataframe in python code. I want to extract the common valves from dataframe and save these common values in next column. I have a column name articles and compare this column with words and save each values to the next column in python dataframe.

image

frame1['C'] = [len(set(article).intersection(words)) for article, words in zip(frame1.article, frame1.words)]

gives me error

TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17260/4070584663.py in <module>
----> 1 frame1['C'] = [len(set(article).intersection(words)) for article, words in zip(frame1.article, frame1.words)]

~\AppData\Local\Temp/ipykernel_17260/4070584663.py in <listcomp>(.0)
----> 1 frame1['C'] = [len(set(article).intersection(words)) for article, words in zip(frame1.article, frame1.words)]

TypeError: 'float' object is not iterable
Timus
  • 10,974
  • 5
  • 14
  • 28
  • [Please do not post images of code, data, error messages, etc.](https://stackoverflow.com/help/how-to-ask) – Timus Apr 18 '22 at 07:43
  • You most likely have `NaN`s in the columns you're using: Their type is float. Try `set("abc").intersection(np.NaN)` and you'll get the same error. You could do a `.fillna("")` before to avoid that. – Timus Apr 18 '22 at 12:22

0 Answers0