1

I have a pandas data frame in which column A has values as lists. the size of the data frame is 14 million rows.

I have another list:

code = ['q23', 'r45', 'y67']

I want to create a new column B in the data frame if any of the values in column A are in code.

any([True if x in df.A if x in code]) doesnt work
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
  • 1
    `df['B'] = df['A'].isin(code)`? – Quang Hoang May 22 '20 at 20:08
  • Does this answer your question? [Filter dataframe rows if value in column is in a set list of values](https://stackoverflow.com/questions/12065885/filter-dataframe-rows-if-value-in-column-is-in-a-set-list-of-values) – deadshot May 22 '20 at 20:10
  • Does this answer your question? [How to filter Pandas dataframe using 'in' and 'not in' like in SQL](https://stackoverflow.com/questions/19960077/how-to-filter-pandas-dataframe-using-in-and-not-in-like-in-sql) – swiss_knight May 22 '20 at 20:44

0 Answers0