close
使用 Pandas 來讀取網頁-台銀幣別轉換兌換並存檔Excel
=============
import pandas as pd
dfs = pd.read_html("http://rate.bot.com.tw/xrt")
type(dfs) #list
len(dfs)
currency= dfs[0]
type(currency) #pandas.core.frame.DataFrame
currency=currency.iloc[:,0:5]
currency.columns=[u"幣別",u"現金匯率-本行買入",u"即期匯率-本行賣出",u"即期匯率-本行賣入",u"即期匯率-本行賣出"]
currency[u"幣別"] = currency[u"幣別"].str.extract("\((\w+)\)") # •\w : 任何大小写字母, 数字和 “” [a-zA-Z0-9]
# + : 重复一次或多次#
print(currency)
currency.to_excel("abc.xlsx")
全站熱搜