Which is the fastest way to extract day, month and year from a given date?

后端 未结 2 581
臣服心动
臣服心动 2020-11-27 19:10

I read a csv file containing 150,000 lines into a pandas dataframe. This dataframe has a field, Date, with the dates in yyyy-mm-dd format. I want t

2条回答
  •  有刺的猬
    2020-11-27 19:44

    I use below code which works very well for me

    df['Year']=[d.split('-')[0] for d in df.Date]
    df['Month']=[d.split('-')[1] for d in df.Date]
    df['Day']=[d.split('-')[2] for d in df.Date]
    
    df.head(5)
    

提交回复
热议问题