Skip to content
Advertisement

convert month of dates into sequence

i want to combine months from years into sequence, for example, i have dataframe like this:

JavaScript

i want to sequence the months of the date. the desired output is:

JavaScript

which means feb’15 is the first month in the date list and jan’2016 is the 12th month after feb’2015

Advertisement

Answer

If your date column is a datetime (if it’s not, cast it to one), you can use the .dt.month and .dt.year properties for this!

https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.month.html

recast

(text copy from Answer to Pasting data into a pandas dataframe)

JavaScript

extract years and months to decimal months and reduce to relative

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement