C2_W2_Assignment, UNQ_C1, Error: Wrong shape

in the UNQ_C1 cell, we are expected to write code that computes the fraction of missing values. This can be achieved by:
df.isnull().any(axis = 1).sum() / df.shape[0]
However, one of the test cases is returning an error related to “Wrong shape”. This can be overcome by simply putting the code inside the funciton float(). That is:
float(df.isnull().any(axis = 1).sum() / df.shape[0])
This way the funciton returns the value as a float rather than an np.float

1 Like


It may help you to check the data type of df.isnull().any(axis = 1).sum() and df.shape[0] by the type() function.

I hope you could confirm that the data type of df.shape[0] is int, whereas that of df.isnull().any(axis = 1).sum() is pd.Series.
This is the reason why you encounter the error related to “wrong shape”.

In the UNQ_C1, we would like to know how many missing values in df, so you should count it and get the integer data type.

Kind regards,

1 Like