0

I have created a function where I need to pass data frame I get shape and return me df.head()

    def shape_of_df(df):
        tup = df.shape
        print('Shape of df  is Rows :{0[0]},column:{0[1]}'.format(tup))
        return df.head()

Now when I call function with items.apply(shape_of_df) I get error however if I call function and pass df as parameter it works fine. Please let me know I am missing something very basic when I use df.apply() couldn't figure out in docs

   shape_of_df(items) # this works fine prints shape and df.head()

1 Answer 1

3

The first line of the docs explains that DataFrame.apply will "Apply a function along an axis of the DataFrame" (i.e., along the rows or along the columns).

You want to apply a function on the entire dataFrame instead, so if you're trying to chain functions, you should look into DataFrame.pipe. The usage is similar:

items.pipe(shape_of_df)

As long as you satisfy the condition that shape_of_df accepts a DataFrame as input and correspondingly returns one as output.

Sign up to request clarification or add additional context in comments.

1 Comment

wow thank you very much I was so dumb and clueless didn't even realize

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.