0

I get error messages with the following code. The peculiar thing is that if I start a debugger, then I can see that within the listcomprehension the dmatr-Object is (as I expected) a Dataframe(view). However, the debugger also shows that within the subsequent invocation of the sumsq function the parameter D is a Series and not a DataFrame. I really don't get it whats happening here. I am just invoking a method (apply) on a DataFrame - yet the functions acts as if the method is invoked on a Series object. Can anyone help me in understanding what is going on here?

d: pandas DataFrame

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
P.Jo
  • 532
  • 3
  • 9
  • 1
    I'm pretty sure `DataFrame.apply` always will pass a Series. It just depends if that Series is a single column, with the DataFrame index or a row that is turned into a Series, indexed by the columns index. – ALollz Dec 05 '19 at 12:06
  • I believe `DataFrame.applymap` is what you need to use if you want to do element-wise operations on an entire dataframe. https://stackoverflow.com/questions/19798153/difference-between-map-applymap-and-apply-methods-in-pandas – Joe Dec 09 '19 at 10:14

0 Answers0