S
S
Sergey Eremin2020-07-06 01:09:58
Python
Sergey Eremin, 2020-07-06 01:09:58

Why don't some pandas.read_excel options work?

Probably a loser question, but something doesn't google the answers.

The parameters convert_float, date_parserand do not work parse_dates.

  • convert_float=True-- not all excel integer values ​​are converted to integer values. The part remains floating point. For example, the value 10 in excel turns into 10.0 ... And you can see that in general there is an integer, but for some reason pandas did not convert. And other values ​​that were convert_float=Falsenot converted with -- do indeed become int
  • How they work date_parserand parse_dates- did not understand at all. Setting it parse_datesto True or False does not change anything. In both cases, the dates are converted to integer values ​​(sometimes with a negative sign, and convert_floatit doesn't even affect them). How to force to work function through date_parser- did not understand.


For example code.

import pandas
from datetime import datetime


def date_format(date):
    # return date.isoformat()
    return 'TEST'


def main():
    # ...
    # ...
    xls_imported = pandas.read_excel(args.XLS_FILE, sheet_name=4, na_values=None,
                                     convert_float=True, mangle_dupe_cols=True,
                                     date_parser=date_format, parse_dates=True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kamenyuga, 2020-07-06
@Sergei_Erjemin

convert_float- in pandas, the type is the same for all values ​​in a column - there is a value in the column that cannot be converted to int. Most often this happens when a value is missing in a column, because an empty value is a Numpy NaN of the float type.
parse_dates- a list of numbers or names of columns that need to be parsed into a date is transmitted - individual columns or groups of columns, if the date is distributed over several.
date_parser- the default parser works fine, although it greatly increases the data loading time. It makes sense to parse the dates separately after loading if the volume is large.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question