pandas – extract month from date in python
pandas – extract month from date in python
import datetime
a = 2010-01-31
datee = datetime.datetime.strptime(a, %Y-%m-%d)
datee.month
Out[9]: 1
datee.year
Out[10]: 2010
datee.day
Out[11]: 31
Alternate solution
Create a column that will store the month:
data[month] = data[date].dt.month
Create a column that will store the year:
data[year] = data[date].dt.year
pandas – extract month from date in python
>>> a=2010-01-31
>>> a.split(-)
[2010, 01, 31]
>>> year,month,date=a.split(-)
>>> year
2010
>>> month
01
>>> date
31