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>I think you have some <code>NaN</code> values, so <code>int</code> are converted to <code>float</code> because <a href="http://pandas.pydata.org/pandas-docs/stable/gotchas.html#na-type-promotions" rel="nofollow">na type promotions</a>.</p>

<p>So you can read data in column <code>label</code> as <code>str</code> and then it works nice:</p>

<pre><code>import pandas as pd
import numpy as np
import io

temp=u"""lab1;label
5;1
5;2
7;
7;3
"""
#after testing replace io.StringIO(temp) to filename
df = pd.read_csv(io.StringIO(temp), sep=';', dtype={'label':str})
print (df)
  lab1 label
0    5     1
1    5     2
2    7   NaN
3    7     3

df['class_label'] = df.label.fillna('')
print (df)
  lab1 label class_label
0    5     1           1
1    5     2           2
2    7   NaN            
3    7     3           3

print (df.to_string(columns=['class_label'],index=False))
class_label
         1
         2

         3
</code></pre>

python pandas decimal tostring