> ## Content Index
> Fetch the complete content index at: https://datascientyst.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to convert month number to month name in Pandas DataFrame
- URL: https://datascientyst.com/convert-month-number-to-month-name-pandas-dataframe/
- Published: 2021-08-18T22:22:17.000Z
- Updated: 2021-12-02T10:54:29.000Z
- Author: John D K
- Tags: Time Series

You can use the following code to **convert the month number to month name in Pandas.**

Full name:

```python
df['date'].dt.month_name()

```

3 letter abbreviation of the month:

```python
df['date'].dt.month_name().str[:3]

```

Next, you'll see example and steps to get the month name from number:

## Step 1: Read a DataFrame and convert string to a DateTime

For example, let's have a DataFrame with a date column inside which is stored a string.

DataFrame and steps are explained here - [How to Search and Download Kaggle Dataset to Pandas DataFrame](https://datascientyst.com/search-download-kaggle-dataset-pandas-dataframe/) or if you use the notebook:

```python
import pandas as pd
df = pd.read_csv('../data/medium_data.csv.zip')
df

```

In case of a date which is stored as a string you can convert it to a datetime by:

```python
df['date'] = pd.to_datetime(df['date'])

```

the data is shown below:

| title                                                                 | date       | claps |
| --------------------------------------------------------------------- | ---------- | ----- |
| A Beginner’s Guide to Word Embedding with Gensim Word2Vec Model       | 2019-05-30 | 850   |
| Hands-on Graph Neural Networks with PyTorch & PyTorch Geometric       | 2019-05-30 | 1100  |
| How to Use ggplot2 in Python                                          | 2019-05-30 | 767   |
| Databricks: How to Save Files in CSV on Your Local Computer           | 2019-05-30 | 354   |
| A Step-by-Step Implementation of Gradient Descent and Backpropagation | 2019-05-30 | 211   |

## Step 2: Convert Month Number to Full Month Name

There are several different ways to get a full month name in Pandas and Python.

First we will show the built in `dt` method - `.dt.month_name()`:

```python
df['month_full'] = df['date'].dt.month_name()

```

This will return the full month name as a new column:

| title                                                                                                                    | date       | claps | month\_full |
| ------------------------------------------------------------------------------------------------------------------------ | ---------- | ----- | ----------- |
| How to Get and Keep Clients as a Freelancer                                                                              | 2019-05-27 | 965   | May         |
| A Battle for the Soul of BreadTube Is Currently Taking Place                                                             | 2019-07-29 | 105   | July        |
| <strong class="markup--strong markup--h3-strong">Business Opportunity: The Colombian Oils and Lubricants Market</strong> | 2019-02-09 | 0     | February    |
| How to know your price is right                                                                                          | 2019-12-05 | 102   | December    |
| 3 Types of Reports That Business Analysts Need to Learn                                                                  | 2019-09-18 | 309   | September   |

## Step 3: Convert Month Number to Month abbreviation

In this step instead of the full month name we will get an abbreviation of the first 3 letters of the name. It's going to use the same method plus `str` slicing:

```python
df['month_short'] = df['date'].dt.month_name().str[:3]

```

The result are short names like:

```
Jul
Mar
Mar
Dec
Aug

```

## Step 4: Convert Month Number to Month name with strftime

One more way to convert a month to it's name is by using the method - `strftime`. This can be done by:

```python
df['date'].dt.strftime('%b')

```

this will return short names as:

```
Jul
Mar
Mar
Dec
Aug

```

For a full month name you can use `%B`:

```python
df['date'].dt.strftime('%B')

```

output:

```
July
March

```

## Step 5: Convert Month Number to custom name with mapping

Finally, what if you like to get custom labels or month names in different languages like Spanish or French.

Then you can apply a custom mapping with `apply`:

```python
import pandas as pd

month_labels = {1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V', 6: 'VI', 7: 'VII', 8: 'VIII',
                9: 'IX', 10: 'X', 11: 'XI', 12: 'XII'}

df['month'] = df['date'].dt.month
df['month'].apply(lambda x: month_labels[x])

```

Above you can find the mapping - `month_labels` which can be updated to suit your needs.

You need also to get the month number by `df['date'].dt.month`

result is:

```
III
VII

```

## Resources

- [Notebook](https://github.com/softhints/datascientyst/blob/master/datetime/3.convert-month-number-to-month-name-pandas-dataframe.ipynb?ref=datascientyst.com)
- [pandas.Series.dt.month\_name](https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.month%5Fname.html?ref=datascientyst.com)
- [pandas.to\_datetime](https://pandas.pydata.org/docs/reference/api/pandas.to%5Fdatetime.html?highlight=to%5Fdatetime&ref=datascientyst.com#pandas.to%5Fdatetime)
- [pandas.Series.dt.strftime](https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.strftime.html?ref=datascientyst.com)