Python Forum
[Pandas] Write data to Excel with dot decimals
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pandas] Write data to Excel with dot decimals
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas keep existing format of Excel AlphaInc 2 1,011 Jan-11-2024, 03:44 AM
Last Post: plonkarchivist
  Grouping in pandas/multi-index data frame Aleqsie 3 669 Jan-06-2024, 03:55 PM
Last Post: deanhystad
  Write from dictionary to excel divon 3 3,726 Jun-11-2023, 10:37 AM
Last Post: Larz60+
  Data Sorting and filtering(From an Excel File) PY_ALM 0 1,045 Jan-09-2023, 08:14 PM
Last Post: PY_ALM
  Increase df column values decimals SriRajesh 2 1,108 Nov-14-2022, 05:20 PM
Last Post: deanhystad
Smile How to further boost the data read write speed using pandas tjk9501 1 1,266 Nov-14-2022, 01:46 PM
Last Post: jefsummers
  Split excel file and write output at specific row and set sheet position DSCA 0 1,990 May-12-2022, 07:29 PM
Last Post: DSCA
Thumbs Up can't access data from URL in pandas/jupyter notebook aaanoushka 1 1,863 Feb-13-2022, 01:19 PM
Last Post: jefsummers
  Help with poorly formatted excel data armitron121 1 1,721 Jan-13-2022, 07:31 AM
Last Post: paul18fr
Question Sorting data with pandas TheZaind 4 2,341 Nov-22-2021, 07:33 PM
Last Post: aserian

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020