1

I have a datframe bankdat with two columns, one with the date in str format, one with floats. I want to use pandas and matplotlib to generate a plot with the x-axis being the dates and the y-axis the floats. I converted the strings to dates using

bankdat['Buchungstag'] = pd.to_datetime(bankdat['Buchungstag'])

When I now try to plot my dataframe using

bankdat.plot()
plt.show()

I get numbers instead of dates on my x-axis:

example

What am I dointg wrong? Thanks for the help PS: I'm new to coding and stackoverflow and would be very grateful if you pointed out things i got wrong

Edit: Thanks for your suggestions. Unfortunatly, using set index yields this plot:fig2. Am i using different distributions than suggested?

Edit2. I am getting the dataframe from a csv file using

ausgaben = pd.read_csv('asd.csv', encoding = 'ISO-8859-1',sep=';', skiprows=6,usecols=[0,7])

after that, i am adding a first row using

bankdat = pd.DataFrame(np.array([[np.nan, '10000']]), columns=[ausgaben.columns[0], ausgaben.columns[1]]).append(ausgaben)

thanks for pointing out the date ordering, i didnt even get to the "thinking weather my data makes sense" stage. The dataframe looks like this: example 3, and exported to csv gives

,Betrag (EUR),Kontostand
,4130.96,4130.96
2016-12-23,-65.0,4065.96
2016-12-20,520.0,4585.96
2016-12-19,-29.5,4556.46
2016-09-12,-1000.0,3556.46

Solved as per Dmitry Polonskiy's suggestion:" It could be the fact that you have a NAT as the first date in your dates column. Try this bankdat.Buchungstag.shift(1).plot()". Thank you for yoyur help!

  • 1
    bankdat.set_index('Buchungstag').plot() ? – MaxU Dec 27 '16 at 14:24
  • i edited my question, thank you! – Djaik Navidson Dec 27 '16 at 16:17
0
bankdat.set_index(['Buchungstag'], inplace = True)
bankdat.index.name = None

bankdat.Buchungstag.plot(figsize=(10,6), title = 'Title', fontsize = 16)
| improve this answer | |
  • thanks, unfortunatly the .buchungstag. format doesnt work on my distributions, using bankdat['Buchungstag'] gives me a key error and i have edited my question with the plot i get if i set the index. – Djaik Navidson Dec 27 '16 at 16:15
  • Can you show what the DF looks like? Seems as if there is a problem with the Buchungstag column as you state. Also seems as if your dates are in reverse order, you might want to sort your DF so that it is in ascending order. – gold_cy Dec 27 '16 at 16:59
  • Should show the column names and if possible the bankdat.head() – gold_cy Dec 28 '16 at 18:06
  • completly misunderstood you, sorry. Edited and thanks! – Djaik Navidson Dec 29 '16 at 3:45
  • It could be the fact that you have a NAT as the first date in your dates column. Try this bankdat.Buchungstag.shift(1).plot() – gold_cy Dec 29 '16 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.