Pandas Creating indicator variables from Dictionary
<p>Say I have the following dataframe:</p>

<pre><code>&gt;&gt;&gt; import pandas as pd
&gt;&gt;&gt; df=pd.DataFrame()
&gt;&gt;&gt; df['Food']=['Orange','Carrot','Apple','Pizza','Cake','Pretzel','Cauliflower']
&gt;&gt;&gt; df
          Food
0       Orange
1       Carrot
2        Apple
3        Pizza
4         Cake
5      Pretzel
6  Cauliflower
&gt;&gt;&gt; 
</code></pre>

<p>And then I have the following dictionary with keys that are categories and values that are a list of values in that category:</p>

<pre><code>&gt;&gt;&gt; FoodClasses
{'Vegetable': ['Carrot', 'Cauliflower'], 'Fruit': ['Orange', 'Apple']}
&gt;&gt;&gt; 
</code></pre>

<p>I want to add columns to my dataframe for each of the two categories (Vegetable and Fruit) and have the columns populated with values indicating whether or not that value is in that category.</p>

<p>I currently do this by looping through each of the categories and get my desired result as such:</p>

<pre><code>&gt;&gt;&gt; for FoodClass in FoodClasses:
...     df[FoodClass]=df['Food'].isin(FoodClasses[FoodClass]).astype(int)
... 
&gt;&gt;&gt; 
&gt;&gt;&gt; df
          Food  Vegetable  Fruit
0       Orange          0      1
1       Carrot          1      0
2        Apple          0      1
3        Pizza          0      0
4         Cake          0      0
5      Pretzel          0      0
6  Cauliflower          1      0
&gt;&gt;&gt; 
</code></pre>

<p>Is there a better way to do this that doesn't involve looping through the dictionary?</p>