我正在使用HTML解析器从网站提取表格,如下所示:
1 Sep 2 Sep 3 Sep 4 Sep
00:00 11 47 54 10
01:00 12 49 46 22
...
23:00 15 34 22 40
但是索引和标头都被识别为对象,而不是日期和小时。那我该如何解决呢?
下面是我正在使用的代码:
url = r'https://www.nratrafficdata.ie/c2/tfmonthreport.asp?sgid=ZvyVmXU8jBt9PJE$c7UXt6&spid=NRA_000000001508&reportdate=2017-09-01&enddate=2017-09-30&sidebar=1'
tables = pd.read_html(url, header=[1], index_col=0)
sp500_table = tables[0]
用途:
df.columns = pd.to_datetime(df.columns, format='%d %a')