我正在从webpage中读取一个表,其中包含多个HTML表,成功读取它们后,我想对其进行重新格式化。我尝试了很多选项,但是我无法正常工作,而且响应是多重的,并且尝试了几乎所有类似df.rename等的方法。 我在下面添加代码和响应,有人可以帮忙吗?
代码:
import uuid
import pandas as pd
class traffic():
def __init__(self):
ssl._create_default_https_context = ssl._create_unverified_context
global homePage
global downloadDir
global filname
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
downloadDir = "C:\\Users\\user\\PycharmProjects\\digitalOcean\\venv\\testDara\\"
uFileName = str(uuid.uuid4())
filname = downloadDir + uFileName + ".csv"
dailyUrl = "https://www.nratrafficdata.ie/c2/tfhourdirection.asp?sgid=ZvyVmXU8jBt9PJE$c7UXt6&spid=NRA_000000001081&reportdate=2018-12-01&enddate=2018-12-01"
iDf = pd.read_html(dailyUrl, index_col=False)
df = iDf[0]
#dff = df.rename({'1':'one', '2':'two'}, axis='columns', inplace=True)
print(df)
if __name__ == '__main__':
objCall = traffic()```
Example response:
check this [1]: https://pasteboard.co/HXPrTVw.png "response"
答案 0 :(得分:0)
使用df.columns = ['ccc','dd','cccs','dd','ddd', 'dddd']