0

I have a series that is purely datetimes. Call it series1.

How can I extract the months from the series in the most efficient way possible to have a new series of just the months?

For example.

series1.month

does not work. But for every row, it would work.

1 Answer 1

2

In Pandas version 0.14 and older, you can use apply to extract the dates from the datetime values:

series1.apply(lambda x: x.month)

In 0.15, a new datetime Series accessor makes the operation much simpler (thanks @chrisb):

series1.dt.month

Here is a link to the documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

In 0.15 you can use the new dt accessor, like series1.dt.month
Thanks @chrisb - I haven't looked at 0.15 yet! I'll add a link to the documentation into the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.