How to create a dummy variable if missing values are included? I have the following data and I want to create a Dummy variable based on several conditions. My problem is that it automatically converts my missing values to 0, but I want to keep them as missing values.
import pandas as pd
mydata = {'x' : [10, 50, np.nan, 32, 47, np.nan, 20, 5, 100, 62],
'y' : [10, 1, 5, np.nan, 47, np.nan, 8, 5, 100, 3]}
df = pd.DataFrame(mydata)
df["z"] = ((df["x"] >= 50) & (df["y"] <= 20)).astype(int)
print(df)