Skip to content

BUG: Value become 0 while exporting (to_excel) the str data #39950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task
handy1988 opened this issue Feb 21, 2021 · 6 comments
Closed
1 task

BUG: Value become 0 while exporting (to_excel) the str data #39950

handy1988 opened this issue Feb 21, 2021 · 6 comments
Labels
IO CSV read_csv, to_csv Usage Question

Comments

@handy1988
Copy link

handy1988 commented Feb 21, 2021

  • [X ] I have checked that this issue has not already been reported.

  • [X ] I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Code Sample, a copy-pastable example

import csv
import pandas as pd

output_csv = pd.read_csv(r"D:\test\output.csv")
output_csv.to_excel(r"D:\test\output.xlsx", index=False)

Problem description

Hi All,
I found some issue while exporting "str" data from some column to excel, And I noticed this issue occurred only after pandas version 1.1.5 and above. And attached my sample of data for your reference. Kindly help to check. Thanks
files.zip

output.csv

Col1,Col2
a1,50060e8007123400
a2,50060e8007123400
a3,50060e8007123400
a4,50060e8007123402
a5,50060e8007123402
a6,50060e8007123402
a7,50060e8007123402
a8,50060e8007123402
a9,50060e8007123404
a10,50060e8007123404

output.xlsx -> Current output

Col1 Col2
a1 0
a2 0
a3 0
a4 0
a5 0
a6 0
a7 0
a8 0
a9 0
a10 0

Expected Output

Col1 Col2
a1 50060e8007123400
a2 50060e8007123400
a3 50060e8007123400
a4 50060e8007123402
a5 50060e8007123402
a6 50060e8007123402
a7 50060e8007123402
a8 50060e8007123402
a9 50060e8007123404
a10 50060e8007123404

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 7d32926
python : 3.9.1.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : English_United States.1252

pandas : 1.2.2
numpy : 1.20.1
pytz : 2021.1
setuptools : 51.1.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.20.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@handy1988 handy1988 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 21, 2021
@MarcoGorelli
Copy link
Member

Hi @handy1988

Could you please put a descriptive title, and also show the output of output_csv as it's just 10 rows?

@handy1988 handy1988 changed the title BUG: BUG: Value become 0 while exporting (to_excel) the str data Feb 21, 2021
@handy1988
Copy link
Author

Hi Marco,

Sorry, I forgot to update the title, now edited already with output of csv. Thanks

@phofl
Copy link
Member

phofl commented Feb 21, 2021

Hm when executing the following:

s = """
Col1,Col2
a1,50060e8007123400
a2,50060e8007123400
a3,50060e8007123400
a4,50060e8007123402
a5,50060e8007123402
a6,50060e8007123402
a7,50060e8007123402
a8,50060e8007123402
a9,50060e8007123404
a10,50060e8007123404
"""

output_csv = pd.read_csv(StringIO(s))

I get

  Col1  Col2
0   a1   0.0
1   a2   0.0
2   a3   0.0
3   a4   0.0
4   a5   0.0
5   a6   0.0
6   a7   0.0
7   a8   0.0
8   a9   0.0
9  a10   0.0

Looks to me as the issue is in read_csv. Also your column is no text data, the e is interpreted as exponent, hence this is numeric

@phofl
Copy link
Member

phofl commented Feb 21, 2021

You can do

output_csv = pd.read_csv(StringIO(s), dtype="object")
output_csv.to_excel(r"output.xlsx", index=False)

to get your result

@handy1988
Copy link
Author

HI phofl,

Thanks for your reply, initially I thought this is a bug since I never faced this issue on previous version. I've tested it and it's working fine. Thanks again for your help👍

@phofl
Copy link
Member

phofl commented Feb 21, 2021

The conversion to 0 is in the same place as #38794, so closing in favor of that issue

@phofl phofl closed this as completed Feb 21, 2021
@phofl phofl added IO CSV read_csv, to_csv Usage Question and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 21, 2021
@phofl phofl added this to the No action milestone Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO CSV read_csv, to_csv Usage Question
Projects
None yet
Development

No branches or pull requests

3 participants