python - Pandas - Reading HTML -
i trying convert this table pandas dataframe
i have done following far
import pandas pd url = 'http://www.scb.se/sv_/hitta-statistik/statistik-efter-amne/befolkning/befolkningens-sammansattning/befolkningsstatistik/25788/25795/helarsstatistik---riket/26046/' df = pd.read_html(url,thousands=' ') df2= df[0] my problem here pandas not recognize index value 0 headers. want column value År index value.
lastly, plot folkmängd column values y , År values x, in line-plot.
thank in advance.
this should close want:
import pandas pd import matplotlib.pyplot plt import matplotlib matplotlib.style.use('ggplot') url = 'http://www.scb.se/sv_/hitta-statistik/statistik-efter-amne/befolkning/befolkningens-sammansattning/befolkningsstatistik/25788/25795/helarsstatistik---riket/26046/' table = pd.read_html(url,thousands=' ', header=0, index_col=0)[0] table["folkmängd"].plot(color='k') plt.show() which should give like:

Comments
Post a Comment