Pandas Python- can datetime be used with vectorized inputs -


my pandas dataframe has year, month , date in first 3 columns. convert them datetime type, use loop loops on each row taking content in first 3 columns of each row inputs datetime function. way can avoid loop here , dates datetime?

i'm not sure there's vectorized hook, can use apply, anyhow:

>>> df = pd.dataframe({"year": [1992, 2003, 2014], "month": [2,3,4], "day": [10,20,30]}) >>> df    day  month  year 0   10      2  1992 1   20      3  2003 2   30      4  2014 >>> df["date"] = df.apply(lambda x: pd.datetime(x['year'], x['month'], x['day']), axis=1) >>> df    day  month  year                date 0   10      2  1992 1992-02-10 00:00:00 1   20      3  2003 2003-03-20 00:00:00 2   30      4  2014 2014-04-30 00:00:00 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -