W3docs

Extracting just Month and Year separately from Pandas Datetime column

You can extract the month and year separately from a Pandas datetime column using the dt accessor.

You can extract the month and year separately from a Pandas datetime column using the dt accessor. Here's an example code snippet:

Extract the month and year separately from a Pandas datetime column using the dt accessor

python— editable, runs on the server
Info

Watch a video course: Python - The Practical Guide

This will create a new column called 'month' and 'year' with the respective values.