硒熊猫数据框构造函数未正确调用

时间:2018-09-24 09:44:38

标签: python pandas selenium

此代码的目的是抓取网页并从表中提取数据,然后将其转换为pandas数据框。

抓取和数据提取进展顺利。

输出如下:

发布日期

时间

实际

预测

上一个

2018年9月9日(八月)

21:30

0.7%

0.5%

0.3%

2018年8月8日(7月)

21:30

0.3%

0.2%

-0.1%

2018年7月9日(6月)

21:30

-0.1%

0.1%

-0.2%

2018年6月8日(5月)

21:30

-0.2%

-0.1%

-0.2%

2018年5月9日(4月)

21:30

-0.2%

-0.1%

-1.1%

2018年4月10日(3月)

21:30

-1.1%

-0.5%

1.2%

2018年3月8日(2月)

21:30

1.2%

0.8%

0.6%

2018年2月8日(1月)

21:30

0.6%

0.7%

0.3%

但是当我尝试将其转换为数据帧时,出现了错误。

代码如下:

FROM microsoft/iis

#Keep the artifacts related for image in the same folder from where docker is running

RUN cmd mkdir C:/DeploymentFiles
WORKDIR C:/DeploymentFiles

# Copy and install msdeploy service
COPY WebDeploy_amd64_en-US.msi .
RUN msiexec /i WebDeploy_amd64_en-US.msi AGREETOLICENSE=yes ADDLOCAL=ALL /qn
RUN powershell Start-service MsDepSvc;

#Remove default iis site's contents
RUN powershell -NoProfile -Command Remove-Item -Recurse C:\inetpub\wwwroot\*


# Resolving 403 issue. Ref - https://github.com/microsoft/iis-docker/issues/5

#Adding a user so i can connect trough IIS Manager
RUN NET USER testing "Password01!" /ADD
RUN NET LOCALGROUP "Administrators" "testing" /add

#Grant Permissions
RUN icacls "C:\inetpub\wwwroot\*" /grant everyone:(OI)(CI)F /T

#Install neccassary features
RUN powershell Install-WindowsFeature Web-Mgmt-Service
RUN powershell Install-WindowsFeature Web-Windows-Auth
RUN powershell Install-WindowsFeature NET-Framework-45-ASPNET
RUN powershell Install-WindowsFeature Web-Asp-Net45
RUN powershell Install-WindowsFeature NET-WCF-HTTP-Activation45

#Start Service and make it autorun
RUN net start wmsvc
RUN sc config WMSVC start= auto
RUN powershell -NoProfile -Command \

Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\WebManagement\Server -Name EnableRemoteManagement -Value 1

# Copy deployment packages and related files to container to "C:/DeploymentFiles"
COPY DeployPackage/ .
# The Deploy_App.bat file contains the command to deploy using msdeploy
COPY Deploy_App.bat .

RUN C:/DeploymentFiles/Deploy_App.bat

# Resolve the ACL issues during deployment. Ref - https://fluentbytes.com/how-to-fix-error-this-access-control-list-is-not-in-canonical-form-and-therefore-cannot-be-modified-error-count-1/
COPY aclFix.ps1 .
RUN powershell.exe -executionpolicy bypass .\aclFix.ps1

RUN C:/DeploymentFiles/Deploy_App.bat

EXPOSE 80

这是错误:

回溯(最近通话最近一次):

文件“ D:/Projects/Tutorial/ff.py”,第22行,在     df = pd.DataFrame(data.strip(),columns = ['Release Date','Time','Actual','Forecast','Previous'])

文件“ C:\ Users \ Sayed \ Anaconda3 \ lib \ site-packages \ pandas \ core \ frame.py”,第422行,初始化     引发ValueError('DataFrame构造函数未正确调用!')

ValueError:DataFrame构造函数未正确调用!

1 个答案:

答案 0 :(得分:1)

只需更改最后一部分

df = pd.DataFrame(columns=['Release Date', 'Time', 'Actual', 'Forecast', 'Previous'])
pos =  0
for table in wait.until(EC.visibility_of_all_elements_located((By.XPATH,'//*[contains(@id,"eventHistoryTable")]//tr'))):
    data = [item.text for item in table.find_elements_by_xpath(".//*[self::td]")]
    if data:
        df.loc[pos] = data[0:5]
        pos+=1
print(df)