3
3

More than 5 years have passed since last update.

PandasでWeb上のTableタグからデータを取得する

Posted at

Pandasの使い方を知りたいので、google colaboratory環境を使って試して行きたい。

パースエンジン(flavor指定)としてBeautifulSoup4を使うので予めインストール

!pip install -q beautifulsoup4

気象庁の「アメダス(表形式)」から東京の前日分データを取得する

import pandas as pd

url = "http://www.jma.go.jp/jp/amedas_h/yesterday-44132.html?areaCode=000&groupCode=30"
tables = pd.read_html(url, flavor='bs4', match="時刻", header=0, index_col=0)

print(tables[0].loc[:,["気温","降水量","湿度"]])

結果


    気温  降水量  湿度
時刻               
時     ℃   mm   %
1   18.0  0.0  54
2   17.6  0.0  55
3   15.5  0.0  66
4   15.1  0.0  70
5   14.9  0.0  73
6   16.2  0.0  70
7   18.9  0.0  56
8   20.3  0.0  50
9   23.0  0.0  51
10  24.3  0.0  49
11  24.5  0.0  47
12  25.2  0.0  48
13  24.7  0.0  47
14  25.1  0.0  37
15  25.7  0.0  35
16  25.2  0.0  36
17  23.7  0.0  42
18  22.2  0.0  48
19  21.7  0.0  53
20  21.4  0.0  53
21  21.1  0.0  57
22  20.6  0.0  67
23  19.2  0.0  80
24  19.0  0.0  80
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3