python - Simple way to plot time series with real dates using pandas -


starting following csv data, loaded pandas data frame...

buchung;betrag;saldo 27.06.2016;-1.000,00;42.374,95 02.06.2016;500,00;43.374,95 01.06.2016;-1.000,00;42.874,95 13.05.2016;-500,00;43.874,95 02.05.2016;500,00;44.374,95 04.04.2016;500,00;43.874,95 02.03.2016;500,00;43.374,95 10.02.2016;1.000,00;42.874,95 02.02.2016;500,00;41.874,95 01.02.2016;1.000,00;41.374,95 04.01.2016;300,00;40.374,95 30.12.2015;234,54;40.074,95 02.12.2015;300,00;39.840,41 02.11.2015;300,00;39.540,41 08.10.2015;1.000,00;39.240,41 02.10.2015;300,00;38.240,41 02.09.2015;300,00;37.940,41 31.08.2015;2.000,00;37.640,41 

... intuitive way plot time series given dates in column "buchung" , monetary values in column "saldo".

i tried

seaborn.tsplot(data=data, time="buchung", value="saldo") 

which yields

valueerror: not convert string float: '31.08.2015' 

what easy way read dates , values , plot time series? assume such common problem there must 3 line solution.

you need convert date column correct format:

data['buchung'] = pd.to_datetime(data['buchung'], format='%d.%m.%y') 

now plot work.


though didn't ask, think run similar problem because numbers (in 'betrag' , 'saldo') seem string well. recommend convert them numeric before plotting. here how can simple string manipulation:

data["saldo"] = data["saldo"].str.replace('.', '').str.replace(',', '.') data["betrag"] = data["betrag"].str.replace('.', '').str.replace(',', '.') 

or set locale:

import locale # data appears in european format, german locale might # fit. try on windows machine: locale.setlocale(locale.lc_all, 'de') data['betrag'] = data['betrag'].apply(locale.atof) data['saldo'] = data['saldo'].apply(locale.atof) # reset locale system default locale.setlocale(locale.lc_all, '') 

on ubuntu machine, follow this answer. if above code not work on windows machine, try locale.locale_alias list available locales , pick name that.


output

using matplotlib since cannot install seaborn on machine working from.

from matplotlib import pyplot plt  plt.plot(data['buchung'], data['saldo'], '-') _ = plt.xticks(rotation=45) 

the plot

note: has been produced using locale method. hence month names in german.


Comments