Creating dictionary from dataframe in python
<p>I want to create a dictionary out of my data frame. Data frame look like this:</p>

<pre><code>Vehical | Brand  | Model Name
car     | Suzuki | abc 
car     | Honda  | def
bike    | Suzuki | xyz
bike    | Honda  | asd
</code></pre>

<p>I want my dictionary like:</p>

<pre><code>{car : {Suzuki : abc, Honda : def}, bike : {Suzuki : xyz, Honda : asd}}
</code></pre>

<p>you can do it this way:</p>

<pre><code>In [29]: df.pivot(index='Vehical', columns='Brand', values='Model Name').to_dict('i')
Out[29]:
{'bike': {'Honda': 'asd', 'Suzuki': 'xyz'},
 'car': {'Honda': 'def', 'Suzuki': 'abc'}}
</code></pre>

<p>result of pivoting:</p>

<pre><code>In [28]: df.pivot(index='Vehical', columns='Brand', values='Model Name')
Out[28]:
Brand   Honda Suzuki
Vehical
bike      asd    xyz
car       def    abc
</code></pre>

python pandas dictionary dataframe