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:
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!
bankdat.set_index('Buchungstag').plot()
? – MaxU Dec 27 '16 at 14:24