title: PySpark - Fillna specific rows based on condition
body: <p>I want to replace null values in a dataframe, but only on rows that match an specific criteria.</p>
  
  <p><strong>I have this DataFrame:</strong></p>
  
  <pre><code>A|B   |C   |D   |
  1|null|null|null|
  2|null|null|null|
  2|null|null|null|
  2|null|null|null|
  5|null|null|null|
  </code></pre>
  
  <p><strong>I want to do this:</strong></p>
  
  <pre><code>A|B   |C   |D   |
  1|null|null|null|
  2|x   |x   |x   |
  2|x   |x   |x   |
  2|x   |x   |x   |
  5|null|null|null|
  </code></pre>
  
  <p><strong>My case</strong></p>
  
  <p>So all the rows that have the number 2 in the column A should get replaced.</p>
  
  <p>The columns A, B, C, D are dynamic, they will change in numbers and names.</p>
  
  <p>I also want to be able to select all the rows, not only the replaced ones.</p>
  
  <p><strong>What I tried</strong></p>
  
  <p>I tried with df.where and fillna, but it does not keep all the rows.</p>
  
  <p>I also though about doing with withColumn, but I only know the column A, all the others will change on each execution.</p>
  
  <p><strong>Adapted Solution:</strong></p>
  
  <pre><code> df.select("A",
               *[
                   when(col("A") == '2', 
                      coalesce(col(c),
                      lit('0').cast(df.schema[c].dataType))
                   ).otherwise(col(c)).alias(c) 
                   for c in cols_to_replace
                 ])
  </code></pre>