How can I keep leading zeros in a column, when I export to CSV?
<p>I am trying to export a dataframe with a column with leading zeros like this: </p>

<pre><code>df["CD_LIN_NEG"]

0     001
1     001
2     004
3     001
4     001
5     001
6     003
7     006
Name: CD_LIN_NEG, dtype: object
</code></pre>

<p>But when I export to csv, all of the leading zeros are cut off any numbers when I open the file in Excel. How can I keep the zeros?</p>

<p>I have tried to convert to string but it doesn't work:</p>

<pre><code>df["CD_LIN_NEG"] = df['T_PROD_CP.LN'].astype(str).apply(lambda x: x.zfill(3))
</code></pre>

<p>or in this way:</p>

<pre><code>df["CD_LIN_NEG"] = '00' + df['T_PROD_CP.LN'].astype(str)
</code></pre>