mmyjh86

[러닝-인강] Globa-Rates #4

Aug 18th, 2020
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2.  
  3. def get_series(df) :
  4.     df = df.iloc[1:]
  5.     df.columns = ["date", "rates"]
  6.     df = df.set_index("date")
  7.     df.index = pd.to_datetime(df.index)
  8.     s = df['rates'].str[:-2]
  9.     return s
  10.  
  11. # convert html to dataframe
  12. url = "https://www.global-rates.com/en/interest-rates/libor/american-dollar/usd-libor-interest-rate-3-months.aspx"
  13. dfs = pd.read_html(url)
  14.  
  15. # convert dataframe to series
  16. s0 = get_series(dfs[14])
  17. s1 = get_series(dfs[15])
  18. s2 = get_series(dfs[16])
  19.  
  20. # write the result to excel file
  21. with pd.ExcelWriter('result.xlsx') as writer:  
  22.     s0.to_excel(writer, sheet_name='Current interest rates')
  23.     s1.to_excel(writer, sheet_name='First rate per month')
  24.     s2.to_excel(writer, sheet_name='First rate per year')
RAW Paste Data