__init_u2;()接受1到6个位置参数,但给出了20个

2024-10-01 02:28:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经从一个网站上提取了结果,结果是在下面的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 

Tags: 数据urldataframepandasdfdatesnapshotload
1条回答
网友
1楼 · 发布于 2024-10-01 02:28:36

您以错误的方式使用参数,下面是函数签名,来自(link

class pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)

数据在哪里

ndarray (structured or homogeneous), Iterable, dict, or 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)

相关问题 更多 >