Skip to content
Advertisement

Modify output of pandas day_name() function

I have a data frame with df name :

JavaScript
InvoiceNumber ProductCode InvoiceDate UnitPrice CustomerId Country
0 489434 85048 2009-12-01 07:45:00 6.95 13085 United Kingdom
1 489434 79323P 2009-12-01 07:45:00 6.75 13085 United Kingdom
2 489434 79323W 2009-12-01 07:45:00 6.75 13085 United Kingdom
3 489434 22041 2009-12-01 07:45:00 2.1 13085 United Kingdom
4 489434 21232 2009-12-01 07:45:00 1.25 13085 United Kingdom

I want a bar plot of my data frame based on number of sold product in each day of week, like this :

enter image description here

I’m use this code :

JavaScript

and i get this plot : enter image description here

I’m have 2 problem :
1- name of days is not short (Monday : Mon)
2- weekdays are not ordered
Any body can help me to solve this problems ?
Thanks

Advertisement

Answer

One solution can be, Use of pandas.Series.dt.dayofweek(The day of the week Monday=0, Sunday=6.) Then use .set_xticklabels to assign the name of day week to the number.

JavaScript

Output: (Generate from random input)

JavaScript

enter image description here

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