Skip to content

ENH: convert datetime components (year, month, day, ...) in different columns to datetime #8158

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

from SO

I didn't find an issue about this, but it has come up some times at stackoverflow: having columns with integers for year, month, day, hour, ..., how do you convert this to a datetime column/index ?

http://stackoverflow.com/questions/19350806/how-to-convert-columns-into-one-datetime-column-in-pandas

You have the typical solution of adding the columns: pd.to_datetime((df['Y']*10000 + df['M']*100 + df['D']).astype('int'), format='%Y%m%d'), and @unutbu added now a faster solution using numpy's different datetime64 resolutions to that question on SO.

I personally think this would be a nice addition to pandas to have a more native solution for this. But then we need to figure out a nice API. Or we keep it as is, but try to document it more (add as example to docs?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions