CSV to Excel conversion using Python
<p>I wrote a piece of code that parse a .csv and save the data in excel format.
The problem is that all my data in excel appear as "number stored as text" and i need the data starting with column 3 to be converted as number type so i can represent it using a chart.
My table is looking something like this:</p>

<pre><code>    C1     C2       C3
R1  BlaBla          36552.00233102 ...
R2         App1     3484.000000000 ...
R3         App2     3399.000000000 ...
.....................................
</code></pre>

<p>and this is the code:</p>

<pre><code>f = open("csv_file")
wb = openpyxl.Workbook()
ws = wb.active
reader = csv.reader(f, delimiter=',')
for i in reader:
    ws.append(i)

f.close()
wb.save("excel_file")
</code></pre>

<p>Does your CSV file contain numeric elements that are in quotation marks? If so, that would result in what you're seeing. For example, consider this:</p>

<pre><code>import openpyxl
wb = openpyxl.Workbook()
ws = wb.active
for i in [['100', 100]]:
    ws.append(i)    
wb.save("excel_file.xlsx")
</code></pre>

<p>The <code>str</code> value is written as a text element in Excel while the <code>int</code> value is written as a number. If your CSV file contains</p>

<pre><code>"100", 100
</code></pre>

<p><code>csv</code> would interpret that as a string and a number.</p>

<p>You could convert everything in column three onwards from your <code>csv</code> file by adding:</p>

<pre><code>i[2:] = [float(x) for x in i[2:]]
</code></pre>

<p>to the line right before you append <code>i</code> to your workbook.</p>

python excel csv openpyxl