1

I have a dataframe with multiple attributes. I have a column amount and a column date which is of format (dd/mm/yyyy hh/mm/ss) or (dd/mm/yyyy). I would like to have the amount on axis y and the date on axis x.

My code here does not raise any errors but the plot is not what I am looking for as it seems that the date is not handled :

import pandas as pd
import matplotlib.pyplot as pplt 
    newAcc['EuroAmount']=newAcc['EuroAmount'].apply(pd.to_numeric)
    newAcc['EuroAmount'].plot(x='AccountingDataCreation')
    pplt.show()

1 Answer 1

1

I think you need Series.plot:

newAcc.set_index('AccountingDataCreation')['EuroAmount'].plot()

Or DataFrame.plot:

newAcc.plot(x='AccountingDataCreation', y='EuroAmount')
Sign up to request clarification or add additional context in comments.

7 Comments

It is weird, it is working I think but my AccountingDataCreation is ordered and my x axis is not ordered, I have 08/02 then 07/02 then 08/02 again
Try convert to datetime by newAcc['AccountingDataCreation'] = pd.to_datetime(newAcc['AccountingDataCreation']) first
ok i'll try, I also found I had a date in another format that might be confusing the algorithm i am changing that
I see you have first days, so newAcc['AccountingDataCreation'] = pd.to_datetime(newAcc['AccountingDataCreation'], dayfirst=True) ?
I finally finished formatting my string to the same format, I tried to apply the to_datetime() and i got a Keyerror :AccountingDataCreation. Is it because i am tryng to setindex() with a date ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.