Himanshu Doneria
Himanshu Doneria

Reputation: 57

TypeError: "value" parameter must be a scalar, dict or Series, but you passed a "DataFrame" in Python

Currently I am breaking on subjected issue. I am not sure why is it breaking and what are the amendments required.

Code:

table = df.pivot_table(values='LoanAmount', index='Self_Employed' ,columns='Education', aggfunc=np.median)

def fage(x):
    return table.loc[x['Self_Employed'],x['Education']]

#Replacing missing values

df['LoanAmount'].fillna(df[df['LoanAmount'].isnull()].apply(fage,axis=1),inplace =True) 

Output:

[15]: df['LoanAmount'].fillna(df[df['LoanAmount'].isnull()].apply(fage,axis=1),inplace =True)

Traceback (most recent call last):

 File "<ipython-input-15-dadf94659135>", line 1, in <module>
    df['LoanAmount'].fillna(df[df['LoanAmount'].isnull()].apply(fage,axis=1),inplace =True)

  File "/home/aryabhatta/anaconda3/lib/python3.6/site-packages/pandas/core/series.py", line 3422, in fillna
    **kwargs)

  File "/home/aryabhatta/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py", line 5400, in fillna
    '"{0}"'.format(type(value).__name__))

TypeError: "value" parameter must be a scalar, dict or Series, but you passed a "DataFrame"

Upvotes: 2

Views: 5387

Answers (1)

Pramod Gaddam
Pramod Gaddam

Reputation: 21

Hi Please make sure that

I hope you didn't execute this line before for filling missing values of LoanAmount

df['LoanAmount'].fillna(df['LoanAmount'].mean(), inplace=True)

The error is the LoanAmount is already filled with other values and there are no missing values in it.so it throws the error.

Replacing missing values:

df['LoanAmount'].fillna(df[df['LoanAmount'].isnull()].apply(fage,axis=1),inplace =True

Before executing above code make sure LoanAmount has missing values execute below command to check.

df.apply(lambda x: sum(x.isnull()),axis=0)

The above command will shows the missing count of LoanAmount. If you have missing values then only you can replace with either fage or mean.

Upvotes: 2

Related Questions