For a DataFrame with 200 rows and 6 columns, what does df.shape return?
Correct answer
B. (200, 6), a tuple of rows then columns
16 views
B. (200, 6), a tuple of rows then columns
16 views
shape returns a tuple in the order rows first, then columns, so the answer is (200, 6). It is an attribute rather than a method, so it is written without parentheses, unlike len(df), which returns only the row count. Confusing the order leads to wrong loops when iterating with df.shape[0] for rows and df.shape[1] for columns.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is B? Ask here and get an explanation.