错误:"未正确调用DataFrame构造函数!"

时间:2018-02-07 13:03:41

标签: python pandas numpy

我正在使用此函数为所有功能创建双向交互(使用sickitLeran函数PolynomialFeatures),但我收到此错误:" DataFrame构造函数未正确调用!" 我的代码是:

def add_interactions(DataFrame):

    combos=list(combinations(list(DataFrame.columns), 2))
    colnames=list(DataFrame.columns) + ['-'.join(x) for x in combos]

    poly = PolynomialFeatures(degree=2)
    DataF = poly.fit(DataFrame)
    print(DataF)
    DataF.columns=colnames
    DataFrame = pd.DataFrame(DataF)

    noint_indicies=[i for i, x in enumerate (list((DataFrame == 0).all())) if x]
    DataFrame = DataFrame.drop(DataFrame.columns[noint_indicies], axis=1)
     return DataFrame

T = add_interactions(X)

   the traceback of the error: 

   ---------------------------------------------------------------------------
   ValueError                                Traceback (most recent call last)
   <ipython-input-61-790b132c4f1d> in <module>()
    1 poly = PolynomialFeatures(degree=2,interaction_only=True, include_bias=False)
   2 DataFrame = poly.fit(X)
    ----> 3 DataFrame = pd.DataFrame(data = DataFrame)
    4 print(DataFrame.head(3))

    ~\Anaconda3\lib\site-packages\pandas\core\frame.py in __init__(self, 
     data, index, columns, dtype, copy)
     402                                          dtype=values.dtype, 
     copy=False)
     403             else:
    --> 404                 raise ValueError('DataFrame constructor not 
    properly called!')
    405 
    406         NDFrame.__init__(self, mgr, fastpath=True)

    ValueError: DataFrame constructor not properly called!

0 个答案:

没有答案