Home > Blockchain >  Modify output of pandas day_name() function
Modify output of pandas day_name() function

Time:08-14

I have a data frame with df name :

>>> df.head()
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 :

fig1 ,ax1 = plt.subplots(figsize=(15, 6))
df["dayName"] = pd.to_datetime(df["InvoiceDate"]).dt.day_name()
df.groupby("dayName").size().plot(ax=ax1, kind="bar", color="lime");

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

CodePudding user response:

One solution can be, Use of enter image description here

  • Related