title: Pandas create multiple columns if not exist in different datasets (the datasets are values of a dictionary)
body: <p>I have the following problem;
  I have a dictionary which contains a dataset in each value (image attached)<a href="https://i.stack.imgur.com/8k1aL.png" rel="nofollow noreferrer">as you will see 57796 and 34733 are the keys and the values are the datasets</a></p>
  <p>So each dataset has different columns, but sharing most of them 7 <code>columns needed_cols = [&quot;osmid&quot;, &quot;geometry&quot;, &quot;highway&quot;, &quot;element_type&quot;, &quot;oneway&quot;, &quot;surface&quot;, &quot;maxspeed&quot;]</code></p>
  <p>Therefore, what I want to do is to iterate over each dataset and keep these 7 columns for each (just these 7 columns) and create them for the datasets which don't have 1, 2, 3 or none of these columns.</p>
  <p>I thought a recursive fn would be a good opt, so I created the following one, and it works, but just for the 1st value, it doesn't work for the rest.</p>
  <pre><code>def setCols(dic, arr):
  for k in dic.keys():
      for col in arr:
          if col not in list(dic[k].columns):
              dic[k][col] = &quot;null&quot;
              return setCols(dic, arr)
          else:
              dic[k] = dic[k][arr]
              return dic
  </code></pre>
  <p>Being &quot;dic&quot; the entire dictionay and &quot;arr&quot; the &quot;needed_cols&quot;
  As far as I understand, this recursive fn should check if each value of &quot;needed_cols&quot; is in each dataset, if it is not, create it with &quot;null&quot; values and start the fn again until the dataset has all the &quot;neede_cols&quot;, or, on the other site, if the dataset has already all the &quot;needed_cols&quot; return the dictionary with each dataset having just the &quot;needed_cols&quot;</p>
  <p>Thanks in advance</p>