Pandas: create dataframe without auto ordering column names alphabetically
<p>I am creating an initial pandas dataframe to store results generated from other codes: e.g.</p>

<pre><code>result = pd.DataFrame({'date': datelist, 'total': [0]*len(datelist), 
                       'TT': [0]*len(datelist)})
</code></pre>

<p>with <code>datelist</code> a predefined list. Then other codes will output some number for <code>total</code> and <code>TT</code> for each <code>date</code>, which I will store in the <code>result</code> dataframe.</p>

<p>So I want the first column to be <code>date</code>, second <code>total</code> and third <code>TT</code>. However, pandas will automatically reorder it alphabetically to <code>TT</code>, <code>date</code>, <code>total</code> at creation. While I can manually reorder this again afterwards, I wonder if there is an easier way to achieve this in one step.</p>

<p>I figured I can also do</p>

<pre><code>result = pd.DataFrame(np.transpose([datelist, [0]*l, [0]*l]),
                      columns = ['date', 'total', 'TT'])
</code></pre>

<p>but it somehow also looks tedious. Any other suggestions?</p>

<pre><code>result = pd.DataFrame({'date': [23,24], 'total': 0,
                       'TT': 0},columns=['date','total','TT'])
</code></pre>

python pandas dataframe