![](/img/trans.png)
[英]How to convert a web scrapped text table into pandas dataframe?
[英]Convert web table to Pandas DataFrame
我正在嘗試將本網站上的下表讀取為Pandas DataFrame
我做了以下
import pandas as pd
url = 'http://www.scb.se/sv_/Hitta-statistik/Statistik-efter-amne/Priser-och-konsumtion/Konsumentprisindex/Konsumentprisindex-KPI/33772/33779/Konsumentprisindex-KPI/272151/'
df = pd.read_html(url,index_col='År')
如何設置這些值: "År Jan Feb Mar Apr Maj Jun Jul Aug Sep Okt Nov Dec Årsmedel"
列值。
預先感謝您的幫助。
似乎您的代碼返回了一個包含單個元素的列表,當您訪問該元素時,它返回了df:
In [36]:
url = 'http://www.scb.se/sv_/Hitta-statistik/Statistik-efter-amne/Priser-och-konsumtion/Konsumentprisindex/Konsumentprisindex-KPI/33772/33779/Konsumentprisindex-KPI/272151/'
df = pd.read_html(url,index_col='År')
df[0]
Out[36]:
Jan Feb Mar Apr Maj Jun Jul Aug Sep Okt \
År
2015 31075 31293 31319 31316 31424 31333 31343 31281 31406 31429
2014 31139 31270 31268 31389 31405 31470 31367 31335 31385 31402
2013 31200 31339 31465 31403 31454 31399 31355 31384 31505 31440
2012 31185 31392 31480 31549 31523 31445 31323 31355 31481 31459
2011 30615 30802 31011 31144 31202 31128 31113 31123 31341 31342
2010 29979 30159 30232 30236 30292 30297 30204 30206 30460 30557
2009 29788 29795 29880 29926 29945 30017 29880 29942 30035 30111
2008 29409 29528 29808 29967 30099 30245 30211 30198 30508 30556
2007 28501 28645 28833 28979 28948 28995 28949 28941 29230 29385
2006 27959 28090 28289 28432 28476 28468 28419 28438 28604 28607
2005 2779 2792 2798 2802 2803 2804 2794 2799 2819 2824
2004 2780 2773 2794 2794 2801 2789 2785 2782 2802 2810
2003 2760 2784 2798 2788 2785 2777 2768 2767 2787 2789
2002 2688 2694 2718 2729 2736 2732 2723 2724 2745 2754
2001 2617 2626 2646 2669 2687 2683 2669 2676 2699 2691
2000 2575 2587 2599 2600 2613 2612 2600 2602 2620 2626
1999 2562 2563 2573 2579 2583 2587 2576 2576 2594 2597
1998 2569 2566 2570 2577 2581 2576 2570 2557 2568 2573
1997 2546 2542 2552 2570 2570 2574 2573 2574 2598 2596
1996 2556 2558 2570 2576 2573 2563 2557 2545 2560 2559
1995 2513 2523 2533 2550 2553 2551 2548 2545 2562 2569
1994 2451 2459 2468 2478 2483 2484 2484 2485 2507 2510
1993 2410 2416 2427 2437 2431 2423 2419 2423 2445 2452
1992 2302 2303 2313 2319 2320 2315 2312 2313 2346 2351
1991 2189 2250 2258 2271 2273 2270 2271 2267 2292 2301
1990 1990 1999 2054 2052 2064 2062 2082 2096 2120 2134
1989 1830 1840 1847 1865 1873 1879 1879 1887 1902 1918
1988 1716 1729 1737 1752 1758 1763 1771 1775 1788 1802
1987 1644 1644 1647 1651 1652 1649 1669 1678 1694 1701
1986 1589 1590 1587 1597 1597 1597 1601 1599 1613 1619
1985 1496 1510 1521 1527 1545 1539 1538 1538 1545 1555
1984 1394 1389 1409 1418 1428 1424 1428 1439 1448 1455
1983 1291 1288 1293 1303 1311 1318 1329 1335 1345 1356
1982 1174 1190 1193 1201 1207 1211 1219 1222 1229 1246
1981 1072 1093 1098 1105 1112 1116 1126 1135 1143 1150
1980 953 968 972 979 982 985 993 999 1027 1042
Nov Dec Årsmedel
År
2015 31375 31421 31335
2014 31356 31405 31349
2013 31420 31504 31406
2012 31382 31461 31420
2011 31416 31478 31143
2010 30658 30873 30346
2009 30103 30169 29966
2008 30306 29899 30061
2007 29575 29632 29051
2006 28643 28643 28422
2005 2817 2818 2804
2004 2794 2794 2792
2003 2783 2786 2781
2002 2747 2751 2728
2001 2692 2695 2671
2000 2627 2625 2607
1999 2590 2596 2581
1998 2567 2562 2570
1997 2592 2591 2573
1996 2553 2549 2560
1995 2568 2560 2548
1994 2508 2504 2485
1993 2453 2443 2432
1992 2340 2349 2324
1991 2311 2308 2272
1990 2141 2139 2078
1989 1922 1928 1881
1988 1805 1809 1767
1987 1707 1707 1670
1986 1619 1623 1603
1985 1565 1571 1538
1984 1464 1488 1432
1983 1364 1375 1326
1982 1256 1259 1217
1981 1154 1149 1121
1980 1048 1052 1000
文檔指出read_html
返回dfs list
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.