I tried to follow this answer but my question is slightly different.
I have two pyspark data frames df2
and bears2
. Both have an integer variable, and I want to create a boolean like this pseudocode:
df3 = df2.withColumn("game", (df2.week_id.isin(bears2.week_if), 1,0))
Basically, if the value of df2
exists in the corresponding column of bears2
, I want a 1
else a 0
I tried the expr()
from the other question, but wasn't able to get it to work. It looked like this:
new_column_1 = F.expr(
"""IF(df2.week_id IN(bears2.week_if), 1, 0))"""
)