Skip to content
Advertisement

Change X Axis Values to Days of Week (Mon – Sun) in Seaborn/Pandas

I’m currently doing a sales analysis I found online, and was wondering how I could display the x axis values (Days of the Week) from their current order to Mon – Sun.

I have grouped the days of the week the item was bought using:

JavaScript

Which returns:

JavaScript

I want this displayed in descending order, and a graph being displayed with Weekday Bought on the x axis and counted Paid values on the y axis. I have my MatplotLib/Seaborn code to create a line graph as:

JavaScript

Which correctly generates a line graph with the correct data on it. I want to adjust this code to display Mon – Sun in order on the x axis. Does anyone know if I could make a list with the days of the week in order, then “plug it in” to my code? Hopefully someone can help me! Thanks!

Note – The Weekday Bought dtype is object

Advertisement

Answer

IIUC, After groupby use reset_index, and do the custom sorting –

JavaScript

OUTPUT:

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