Skip to content
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

In read_excel parse_date=False is not working #29217

Closed
ajphukan opened this issue Oct 25, 2019 · 8 comments · Fixed by #29796
Closed

In read_excel parse_date=False is not working #29217

ajphukan opened this issue Oct 25, 2019 · 8 comments · Fixed by #29796
Labels

Comments

@ajphukan
Copy link

Code Sample, a copy-pastable example if possible

import pandas as pd
df = pd.read_file('filename.xlsx', header= None, skiprows=1, parse_dates=False)

Problem description

In read_excel parse_date default value is False , but still it is parsing the date.

Note: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!

Note: Many problems can be resolved by simply upgrading pandas to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check if master addresses this issue, but that is not necessary.

For documentation-related issues, you can check the latest versions of the docs on master here:

https://pandas-docs.github.io/pandas-docs-travis/

If the issue has not been resolved there, go ahead and file it in the issue tracker.

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None
python : 3.6.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None

pandas : 0.25.2
numpy : 1.14.4
pytz : 2019.3
dateutil : 2.8.0
pip : 19.3.1
setuptools : 41.4.0
Cython : None
pytest : 5.2.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.1
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : None
sqlalchemy : 1.0.8
tables : None
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None

@hwalinga
Copy link
Contributor

Can you maybe share the file (or something we can reproduce this with) that causes this problem?

The parse_dates can only be used in a specific case. Citing the documentation:

But if you have a column of strings that look like dates (but are not actually formatted as dates in excel), ...

So, this can only be used for columns that have strings that might be interpreted as dates, and not for column that are already the date type in excel itself.

@ajphukan
Copy link
Author

ajphukan commented Oct 25, 2019

Input sample you can use combination of date and simple string
`
col

aaaa
12/10/2019
ppp
cc
12/10/2019

`

Output that I am getting:

aaaa
2019-12-10 00:00:00
ppp
cc
2019-12-10 00:00:00

@hwalinga
Copy link
Contributor

I was looking for the actual binary file 'filename.xlsx'.

@gfyoung
Copy link
Member

gfyoung commented Oct 25, 2019

My guess is that the Excel file is defining the data format of those cells as date:

def _parse_cell(cell_contents, cell_typ):
"""converts the contents of the cell into a pandas
appropriate object"""
if cell_typ == XL_CELL_DATE:
# Use the newer xlrd datetime handling.
try:
cell_contents = xldate.xldate_as_datetime(cell_contents, epoch1904)
except OverflowError:
return cell_contents
# Excel doesn't distinguish between dates and time,
# so we treat dates on the epoch as times only.
# Also, Excel supports 1900 and 1904 epochs.
year = (cell_contents.timetuple())[0:3]
if (not epoch1904 and year == (1899, 12, 31)) or (
epoch1904 and year == (1904, 1, 1)
):
cell_contents = time(
cell_contents.hour,
cell_contents.minute,
cell_contents.second,
cell_contents.microsecond,
)

For those types of cells, we are rendering those as date because Excel told us to do so.

The parameter parse_dates, however, applies to entire columns i.e. we convert the entire column of data to date, which doesn't seem to be happening here.

@jbrockmendel jbrockmendel added the IO Excel read_excel, to_excel label Oct 26, 2019
@ajphukan
Copy link
Author

@gfyoung Yes the problem is with the microsoft excel, It is detecting the cell type automatically to date, I had to convert it to Text to avoid the auto parsing of cell to date type.

Can we include this Info in the doc so that new users can get the answer without raising issue ..

@gfyoung
Copy link
Member

gfyoung commented Oct 28, 2019

@ajphukan : You are more than welcome to contribute something!

@vishwasshrikhande
Copy link

I want to help, how do i start by adding this info to the doc? Any help

@hwalinga
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
5 participants