0

I am creating new columns for a df but I would like to include an if statement while doing so. My df is just a column of dates.

      date
2020-01-01
2020-01-02
       ...

I want to check if a key is in a list. If yes the df[col] = 1, else 0. The key is equal to str(x + y + date)

for x in list1:

    for y in list2:

        df[col] = if str(x + y + df['date']) in keylist: 1, else: 0

What would be the best way to structure this? Thank you!

johnboy
  • 111
  • 1
  • 6

1 Answers1

1

you need to reorder your if statement. This should work:

df[col] = 1 if str(x + y + df['date']) in keylist else 0

Check out this post.

cmosig
  • 1,187
  • 1
  • 9
  • 24