title: Filling null and not null values as 0 and 1, respectively to only selected columns in pyspark dataframe
body: <p>For a sample spark df:</p>
  <pre><code>sdf = ({'id_col': [25, 13, 15],
                     'x2': ['b', None, '2'],
                     'x3': [None, '0', '3'] })
  </code></pre>
  <p>which I would to have:</p>
  <pre><code>sdf = ({'id_col': [25, 13, 15],
                     'x2': [1, 0, 1],
                     'x3': [0, 1, 1] })
  </code></pre>
  <p>replace all null with 0, and notnull with 1.</p>
  <p>Following the syntax from: <a href="https://stackoverflow.com/questions/51381038/filling-not-null-values-as-1-in-pyspark-dataframe">Filling not null values as 1 in pyspark dataframe</a>. it went trough all the columns of the sdf. For my case, I need to keep the values of id_col as is but replace with 1 and 0 on cols x2 and x3.</p>
  <p>I initially tried the following:</p>
  <p>I put the x2 and x3 cols in a list:</p>
  <p>list = ['x2','x3']</p>
  <p>then applied this:</p>
  <pre><code>col_selection = [when(col(c).isNull(),0).otherwise(1).alias(c) for c in sdf[[list]].columns]
  </code></pre>
  <p>I get the intended 0s and 1s, but I only get the x2 and x3 columns. When I called the sdf, the changes did not happen. If I have 17 columns to go through in a 25-column sdf, can you guide me on how to apply the for loop on only the 17 columns?</p>
  <p>Thanks</p>