我从一个网站中提取了结果,其他93个计划的结果格式如下。我已经创建了一个数据框来存储此信息,以后再将此数据框导出到csv文件中。但是,我遇到错误了
Traceback (most recent call last):
File "C:/Study/Web_Crawl/Test_WebC.py", line 104, in <module>
df = pandas.DataFrame('Snapshot Date', 'URL', 'planId', 'postcode', 'tariffType', 'planName', 'retailerName',
TypeError: __init__() takes from 1 to 6 positional arguments but 20 were given
df = pandas.DataFrame('Snapshot Date', 'URL', 'planId', 'postcode', 'tariffType', 'planName', 'retailerName',
'retailerCode', 'state', 'effectiveDate', 'solarFit', 'discount', 'dailySupplyCharge',
'Controlled Load 1', 'Controlled Load 2', 'Single Rate', 'Off-Peak', 'Peak', 'Shoulder')
结果样本
Snapshot date 2020-08-02
URL https://api.energymadeeasy.gov.au/plans/dpids/PWR93173MBE1?postcode=2000
planId PWR93173MBE1
postcode 2000
tariffType SR
planName Powerbank Bis Flat
retailerName Powerclub
retailerCode PWR
state NSW
effectiveDate 2020-07-15
solarFit
discount
dailySupplyCharge 162.9629
Controlled Load 1
Controlled Load 2
Single Rate 17.9203
Off-Peak
Peak
Shoulder
答案 0 :(得分:0)
您使用了错误的参数,下面是(link)中的函数签名
class pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)
数据在哪里
ndarray(结构化或同类),可迭代,dict或DataFrame
所以您应该执行以下操作:
data_array = ['Snapshot Date', 'URL', 'planId', 'postcode', 'tariffType', 'planName', 'retailerName',
'retailerCode', 'state', 'effectiveDate', 'solarFit', 'discount', 'dailySupplyCharge',
'Controlled Load 1', 'Controlled Load 2', 'Single Rate', 'Off-Peak', 'Peak', 'Shoulder']
df = pandas.DataFrame(data=data_array)