title: Make and populate a PySpark dataframe with columns as period_range
body: <p>I have a PySpark dataframe like this</p>
  
  <pre><code>+----------+--------+----------+----------+
  |id_       | p      |d1        |  d2      |
  +----------+--------+----------+----------+
  |  1       | A      |2018-09-26|2018-10-26|
  |  2       | B      |2018-06-21|2018-07-19|
  |  2       | B      |2018-08-13|2018-10-07|
  |  2       | B      |2018-12-31|2019-02-27|
  |  2       | B      |2019-05-28|2019-06-25|
  |  3       |C       |2018-06-15|2018-07-13|
  |  3       |C       |2018-08-15|2018-10-09|
  |  3       |C       |2018-12-03|2019-03-12|
  |  3       |C       |2019-05-10|2019-06-07|
  | 4        | A      |2019-01-30|2019-03-01|
  | 4        | A      |2019-05-30|2019-07-25|
  | 5        |C       |2018-09-19|2018-10-17|
  -------------------------------------------
  </code></pre>
  
  <p>From this I want to create and populate another Pyspark dataframe which have <code>n</code> columns ranging from <code>min(d1)</code> to <code>max(d2)</code> and each column is a date in that range.</p>
  
  <p>I want to populate this dataframe with 1 and 0 for each row.</p>
  
  <p>For row 1 I want populate all the days in the range min(d1 of row 1) to max(d1 of row 1) with <code>1</code> and rest columns with a <code>0</code>. Similarly for all the rows in the dataframe.</p>
  
  <p>I was doing something like this in pandas for this purpose.</p>
  
  <pre><code>result = pd.DataFrame(data = 0, columns=pd.period_range(data['d1'].min(), data['d2'].max(), freq='D'), index=data.index)
  
  for c in result.columns:
      result[c] = np.where((c.d2&gt;=data.d1)&amp;(c.d1 &lt;= data.d2), 1, 0)
  </code></pre>
  
  <p>How to do the same in PySpark.? </p>