convert decimal to string python
<p>I imported tab delimited file to create a dataframe (<code>df</code>) which has the following <code>label</code>:</p>

<pre><code>label
1
2

3

1
</code></pre>

<p>This is stored as pandas.core.series.Series and I want to convert it to string format so that I can get rid of the decimals when I write this out to a text file.</p>

<pre><code>df.class_label=df.label.fillna('')
df.to_string(columns=['label'],index=False)
</code></pre>

<p>The variable type is still <code>Series</code>, and output (text file) also has the decimals:</p>

<pre><code>1.0 2.0  3.0  1.0
</code></pre>

<p>How to get rid of these decimals?</p>

<p>You can use the <code>float_format</code> keyword argument of the <code>to_string()</code> method:</p>

<pre><code>df.to_string(columns=['label'], index=False, float_format=lambda x: '{:d}'.format(x))
</code></pre>

python pandas decimal tostring