osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Silent data corruption in pandas


Peter Otten wrote:

[Practising the bad habit of public soliloquy]

> def parse_datetime(dt):
>     return datetime.datetime.strptime(
>         dt.replace(".", ":"), "%Y-%m-%d %H:%M:%S"
>     )
> 
> 
> def date_parser(dates, times):
>     return numpy.array([
>         parse_datetime(date + " " + time)
>         for date, time in zip(dates, times)
>     ])

This can be rewritten:

@numpy.vectorize
def date_parser(date, time):
    return datetime.datetime.strptime(
        date + " " + time.replace(".", ":"),
        "%Y-%m-%d %H:%M:%S"
    )