Skip to content

BUG: pd.read_excel writing numbers with .0 in string column when using an Excel file downloaded from Google Sheets #46810

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
2 of 3 tasks
eliasmistler opened this issue Apr 20, 2022 · 6 comments
Labels
Bug Closing Candidate May be closeable, needs more eyeballs IO Excel read_excel, to_excel

Comments

@eliasmistler
Copy link

eliasmistler commented Apr 20, 2022

Pandas version checks

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

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

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

path = "~/Downloads/test-from-gsheets.xlsx"
pd.read_excel(path)

Issue Description

It seems like Pandas behaves differently with Excel files downloaded from Google Sheets than with those created in Excel. Namely, with files from Google Sheets, I get .0 decimal points for columns with mixed data types (which does not happen in regular Excel files).

To reproduce: Create a new spreadsheet file in Google Drive and download as Excel. Can be as simple as one column, as long as it has numeric and string-like values:

Test
ABC123
234

When reading this file with pd.read_excel, you get the following output (with the added .0 in the string):

Test
ABC123
234.0

Funnily enough, when I create the same file directly in Excel, I don't get the added .0 and it works fine. I was even able to fix the behaviour by opening the downloaded file in Excel and saving it again.

test-from-local.xlsx
test-from-gsheet.xlsx

Expected Behavior

Mixed type columns are read as object type, without trailing .0, independent of whether the Excel file was created in Excel or Google Sheets.

Installed Versions

INSTALLED VERSIONS

commit : 4bfe3d0
python : 3.9.5.final.0
python-bits : 64
OS : Darwin
OS-release : 21.4.0
Version : Darwin Kernel Version 21.4.0: Mon Feb 21 20:36:53 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T8101
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 1.4.2
numpy : 1.22.3
pytz : 2022.1
dateutil : 2.8.2
pip : 22.0.4
setuptools : 52.0.0.post20210125
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli :
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None

@eliasmistler eliasmistler added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 20, 2022
@eliasmistler
Copy link
Author

Quick update: The column is being read in as object, but it's not str values throughout. Some of the values are actually float and only converted to strings with decimal points later in data processing. Still curious that this is not the case with Excel-generated files

@rhshadrach
Copy link
Member

Thanks for the report! Can you upload the excel files (one created and downloaded via Google docs, and the other via Excel) to the OP.

@rhshadrach rhshadrach added IO Excel read_excel, to_excel Needs Info Clarification about behavior needed to assess issue labels Apr 21, 2022
@eliasmistler
Copy link
Author

No worries - both files are uploaded now. I unzipped both files as well and compared the content. Turns out the version from Google Sheets does actually store the number as 234.0 which would explain where Pandas gets it from...

@rhshadrach
Copy link
Member

I see; it seems to me we would want to persist the .0 as is currently happening.

@rhshadrach rhshadrach added Closing Candidate May be closeable, needs more eyeballs and removed Needs Info Clarification about behavior needed to assess issue Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 21, 2022
@ahawryluk
Copy link
Contributor

I believe this issue is a duplicate of #46988 and has been resolved by #47121 in the forthcoming pandas 1.4.3.

@mroeschke
Copy link
Member

Yes, this appears as a duplicate and will be fixed in the next point release. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Closing Candidate May be closeable, needs more eyeballs IO Excel read_excel, to_excel
Projects
None yet
Development

No branches or pull requests

4 participants