What does df["price"] return for a DataFrame df in pandas?
Correct answer
C. A Series holding that single column
13 views
C. A Series holding that single column
13 views
Bracket selection with a single label returns a Series, a one-dimensional labelled array whose index is the DataFrame's row index. Selecting with a list, df[["price"]], returns a DataFrame instead, which matters when downstream code expects two dimensions. Use .to_numpy() explicitly if a raw NumPy array is required, since pandas does not return one implicitly.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.