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")

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 ricky10116r2d2 的頭像
    ricky10116r2d2

    ricky10116r2d2的部落格

    ricky10116r2d2 發表在 痞客邦 留言(0) 人氣()