Download Taiwan local weather data for advanced analysis and application.
Install python libraries with requirements.txt in src folder.
pip install -r requirements.txt
You can reach the information table of CWB stations on CWB e-service.
Or you can also extract the table as following:
webpage = "https://e-service.cwb.gov.tw/wdps/obs/state.htm"
read_html = pd.read_html(webpage)
html_table = read_html[0]
html_df = html_table.loc[:, ["站號", "站名", "海拔高度(m)", "城市", "經度", "緯度", "地址"]]
display(html_df)
Get the station number and the station name you need.
Take the date-time, station number, altitude, and the station name with the url below.
Then, you will gather the data of 2020-01-01 at Taipei station.
- The Mandarin characters in the station name must be transcoded twice with urllib.
- There is some problems with requests library for merging the url, so using F-string here.
stnum = "466920"
stname = urllib.parse.quote(urllib.parse.quote("臺北"))
date = datetime.date(2020, 1, 1)
altitude = "1017.5m"
html_data = pd.read_html(F"https://e-service.cwb.gov.tw/HistoryDataQuery/DayDataController.do?command=viewMain&station={stnum}&stname={stname}&datepicker={date}&altitude={altitude}")
Use a for-loop to download the rest data of 2020.
Check the weather data with a chain chart.
Now, you have the hourly data of 2020 at Taipei for analysis and advanced application to other fields.
This repository is recently packaged as a WebAPI for a test.
You can try the WebAPI here: @Taiwan Weather Downloader API
If there are any questions/problems with using the API, please don't hesitate to contact me.