-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: convert datetime components (year, month, day, ...) in different columns to datetime #8158
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
Comments
I think we tried to doc this some where (or cookbook - don't remember offhand) how about pd.to_datetime(DataFrame, format could also be list of these columns I guess as well (this is more powerful though; a list would have to be unambiguously Ymd) |
How about adding a helper function like
It would be easier than adding the functionality to
|
I like @unutbu's A couple of thoughts:
|
@unutbu want to do a PR for this? |
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?)
The text was updated successfully, but these errors were encountered: