我得到了以下代码的错误消息。奇怪的是,如果我启动一个调试器,那么我可以看到在listcomprehension中,dmatr对象(正如我所期望的)是一个数据帧(视图)。 但是,调试器还显示,在sumsq函数的后续调用中,参数D是一个系列,而不是数据帧。我真的不明白这里发生了什么。我只是在数据帧上调用一个方法(apply)——但是函数的行为就像是在一个Series对象上调用该方法一样。有人能帮我理解这里发生了什么吗
d:数据帧
import pandas as pd
import numpy as np
import collections
from sklearn.linear_model import LogisticRegression
def fisher(d, colIndex=0):
k = d.shape[1] #number of variables
sel = list(map(lambda x: x != colIndex, list(range(0, k))))
dfull = d.iloc[:, sel]
zw = dfull.groupby(d.iloc[:, colIndex])
def sumsq(D):
return D #when invoked from the subsequent line, the passed argument seems to be a Series!
return [dmatr.apply(sumsq) for (name, dmatr) in zw] #herein dmatr is a DataFrame
目前没有回答
相关问题 更多 >
编程相关推荐