1

I was trying to plot a graph from a dataframe that was created using pivoting a raw csv file. I tried to put the index "Month" as x-axis at the time of plotting using xticks

(ax = df.plot(xticks=df.index)
ylab = ax.set_ylabel('Device sold')

But everytime one error comes after executing the code:

f'units: {x!r}') from e matplotlib.units.ConversionError: Failed to convert value(s) to axis units: Index(['April', 'August', 'February', 'January', 'July', 'June', 'March', 'May'], dtype='object', name='Month')

The data where i tried to plot the above code is as below :

[Pivoted data][1][1]: https://i.stack.imgur.com/wqq51.png

Omar Hasib
  • 29
  • 4
  • 2
    How working `ax = df.plot()` ? – jezrael Aug 26 '19 at 05:27
  • 1
    @jezrael, this is providing an output keeping index as x-axis as required but in y axis all others parameters are showing which is not demanding – Omar Hasib Aug 26 '19 at 06:06
  • 2
    Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](http://stackoverflow.com/help/how-to-ask) may also be useful. – jezrael Aug 26 '19 at 06:08
  • 1
    [Provide a copy of the DataFrame](https://stackoverflow.com/questions/52413246/how-do-i-provide-a-reproducible-copy-of-my-existing-dataframe) as no one wants to recopy the data by hand. – Trenton McKinney Aug 26 '19 at 06:41
  • `sample_data=pd.read_csv('Finance-REPORT-mProduct21-08-2019.csv') Revenue=pd.pivot_table(sample_data,index="Month",values='Invoice Amount',aggfunc='sum') Revenue = Revenue.reindex(Month_order).dropna() df = pd.DataFrame(Revenue) df.rename(columns={'Invoice Amount':'Total Revenue Earn (BDT)'}, inplace=True) df2 = df.insert(1,"Total Online Payment (BDT) ",b,False) . . . df11 = df.insert(10,"Total Revenue Loss (BDT) ",k,False) df12 = df.insert(11,"Total Successful Order",l,False) ax = df.plot(xticks=df.index) ylab = ax.set_ylabel('Device Sold') – Omar Hasib Aug 26 '19 at 15:20
  • Edit your question, and and the data there, not in a comment. – Trenton McKinney Aug 26 '19 at 15:34

0 Answers0