Python Forum
[Pandas] Write data to Excel with dot decimals - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: [Pandas] Write data to Excel with dot decimals (/thread-33558.html)



[Pandas] Write data to Excel with dot decimals - manonB - May-05-2021

Hello everyone,

I looked everywhere but I can't seem to find a solution to my problem.
I have a text file containing data with decimal type '.'. Using read_csv, I import the data to python. The problem is that when I want to write it to Excel my data get ',' decimal type. I want to keep the '.'.
Does anyone know how to solve the problem ?

Here is the code I used :
import numpy as np
import pandas as pd 

fileName="exemple.txt"

data = pd.read_csv(fileName, sep=";") # on récupère les données des fichiers dans un tableau

writer = pd.ExcelWriter(fileName.split('.',2)[0]+'.xlsx',engine='xlsxwriter')

data.to_excel(writer,index=False,header=None) # on recopie les tableaux de données dans les fichiers excel

writer.save()
My text file contains these 2 lines
6.02382e-009;-0.0157154
0.0252904;0.0352284


Thanks in advance,
Manon


RE: [Pandas] Write data to Excel with dot decimals - ibreeden - May-05-2021

It is an Excel setting which defines how numbers are shown: with a decimal point or a decimal comma.
It is described here: Change the decimal point to a comma or vice versa.