Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- def get_series(df) :
- df = df.iloc[1:]
- df.columns = ["date", "rates"]
- df = df.set_index("date")
- df.index = pd.to_datetime(df.index)
- s = df['rates'].str[:-2]
- return s
- # convert html to dataframe
- url = "https://www.global-rates.com/en/interest-rates/libor/american-dollar/usd-libor-interest-rate-3-months.aspx"
- dfs = pd.read_html(url)
- # convert dataframe to series
- s0 = get_series(dfs[14])
- s1 = get_series(dfs[15])
- s2 = get_series(dfs[16])
- # write the result to excel file
- with pd.ExcelWriter('result.xlsx') as writer:
- s0.to_excel(writer, sheet_name='Current interest rates')
- s1.to_excel(writer, sheet_name='First rate per month')
- s2.to_excel(writer, sheet_name='First rate per year')
Add Comment
Please, Sign In to add comment