2026, Jan 02 03:00
Convert English month abbreviations to French in a pandas DataFrame: Series vs list, apply or replace
Learn how to convert English month abbreviations to French in a pandas DataFrame without locale. Compare apply vs replace and avoid Series vs list errors.
Converting month abbreviations in a pandas DataFrame to their French names sounds trivial until you run into edge cases like calling methods on plain Python lists or mixing up where the transformation should happen. The task is to map EN month labels like Jan, Feb, Mar to Janvier, Février, Mars inside a column, without relying on locale settings.
Problem setup
The core logic is a function that maps English month abbreviations to their French counterparts. The data source provides a column via something like frame["month"] = frame["ic_graph"]["month"].tolist(), and the goal is to display the months in French. The solution must not use locale.setlocale.
def month_to_fr(label):
global ActiveMonth
match label:
case "Jan":
return "Janvier"
case "Feb":
return "Février"
case "Mar":
return "Mars"
case "Apr":
return "Avril"
case "May":
return "Mai"
case "Jun":
return "Juin"
case "Jul":
return "Juillet"
case "Aug":
return "Août"
case "Sep":
return "Septembre"
case "Oct":
return "Octobre"
case "Nov":
return "Novembre"
case "Dec":
return "Décembre"
case _:
return ""
# Example source assignment
frame["month"] = frame["ic_graph"]["month"].tolist()
What’s going on and why it breaks
A common pitfall is mixing up pandas Series and plain Python lists. When you do .tolist(), you get a list. Lists don’t have DataFrame/Series methods like replace, so calling those on a list triggers errors such as 'list' object has no attribute 'replace'. If you want to transform values element-wise, either work on the Series with .apply, or transform the list using a comprehension before or after assigning it to the column.
Solution
If you want to modify the DataFrame column itself, apply the conversion function to the Series. This keeps everything inside pandas and produces the expected French month names.
def en_to_fr_month(x):
if x == "Jan":
return "Janvier"
elif x == "Feb":
return "Février"
elif x == "Mar":
return "Mars"
elif x == "Apr":
return "Avril"
elif x == "May":
return "Mai"
elif x == "Jun":
return "Juin"
elif x == "Jul":
return "Juillet"
elif x == "Aug":
return "Août"
elif x == "Sep":
return "Septembre"
elif x == "Oct":
return "Octobre"
elif x == "Nov":
return "Novembre"
elif x == "Dec":
return "Décembre"
else:
return ""
# Update the existing column with French month names
frame["month"] = frame["month"].apply(en_to_fr_month)
If you only need a transformed list for output without touching the DataFrame, use a list comprehension on the list you already have.
french_labels = [en_to_fr_month(v) for v in frame["ic_graph"]["month"].tolist()]
There is also a direct substitution route using pandas replacement with a dictionary mapping. This avoids a custom function while achieving the same effect.
frame["month"] = frame["month"].replace({
"Jan": "Janvier",
"Feb": "Février",
"Mar": "Mars",
"Apr": "Avril",
"May": "Mai",
"Jun": "Juin",
"Jul": "Juillet",
"Aug": "Août",
"Sep": "Septembre",
"Oct": "Octobre",
"Nov": "Novembre",
"Dec": "Décembre"
})
Why this matters
Distinguishing between Python lists and pandas Series saves time and avoids confusing attribute errors. Applying transformations at the right abstraction layer keeps the pipeline predictable and easier to reason about. Whether you choose a function with .apply, a comprehension for ad hoc output, or a dictionary-based .replace, the crucial part is to operate on the correct type.
Takeaways
Keep the mapping explicit when you can’t or don’t want to use locale. Apply transformations to Series if you’re changing DataFrame content, and use comprehensions when you only need a transformed list. If all you need is a straight value substitution, a dictionary with .replace is concise and readable. These patterns make the month label conversion to French reliable and maintainable in a pandas workflow.