如何识别熊猫索引和标题中的日期?

问题描述 投票:0回答:1

我正在使用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]
python html python-3.x pandas html-parsing
1个回答
0
投票

用途:

df.columns = pd.to_datetime(df.columns, format='%d %a')
© www.soinside.com 2019 - 2024. All rights reserved.