-1

What is the difference between df.iloc[[i]] and df.iloc[i]?

I recognize df.iloc[[i]] represents matrix's i-row (parallel shape), but de.iloc[i] represents matrix's i-row as like Vertical shape.

I wonder why de.iloc[i] shows vertical shape.

Ravi
  • 2,778
  • 2
  • 20
  • 32
keenshark
  • 19
  • 3
  • 2
    Does this answer your question? [pandas loc vs. iloc vs. at vs. iat?](https://stackoverflow.com/questions/28757389/pandas-loc-vs-iloc-vs-at-vs-iat) – Ravi Dec 19 '20 at 17:31
  • 1
    That is a different question asking about the difference between 3 methods. This question is asking about the way one method interprets different types of inputs. – DavidN Dec 20 '20 at 22:19

1 Answers1

1

A different object type is returned in each instance.

When you pass a scalar integer [0] it returns a Series object.

When you pass a list of integers [[0]] (this is a list of length 1) it returns a DataFrame object.

You can see for yourself by running: type(df.iloc[i]) vs type(df.iloc[[i]]).

See pandas.DataFrame.iloc documentation.

DavidN
  • 630
  • 1
  • 4
  • 13