Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
format code
Source Link
buhtz
  • DataFrame.loc()DataFrame.loc() : Select rows by index value
  • DataFrame.iloc()DataFrame.iloc() : Select rows by rows number

example Example:

  1. Select first 5 rows of a table, df1 is your dataframe

Select first 5 rows of a table, df1 is your dataframe

df1.iloc[:5]

df1.iloc[:5]
  1. Select first A, B rows of a table, df1 is your dataframe

Select first A, B rows of a table, df1 is your dataframe

df1.loc['A','B']

df1.loc['A','B']
  • DataFrame.loc() : Select rows by index value
  • DataFrame.iloc() : Select rows by rows number

example :

  1. Select first 5 rows of a table, df1 is your dataframe

df1.iloc[:5]

  1. Select first A, B rows of a table, df1 is your dataframe

df1.loc['A','B']

  • DataFrame.loc() : Select rows by index value
  • DataFrame.iloc() : Select rows by rows number

Example:

Select first 5 rows of a table, df1 is your dataframe

df1.iloc[:5]

Select first A, B rows of a table, df1 is your dataframe

df1.loc['A','B']
added 4 characters in body
Source Link
atline
  • DataFrame.loc() : Select rows by index value
  • DataFrame.iloc() : Select rows by rows number

DataFrame.loc() : Select rows by index value , DataFrame.iloc() : Select rows by rows number exampleexample :

  1. Select first 5 rows of a table, df1 is your dataframe

df1.iloc[:5]

  1. Select first A, B rows of a table, df1 is your dataframe

df1.loc['A','B']

DataFrame.loc() : Select rows by index value , DataFrame.iloc() : Select rows by rows number example :

  1. Select first 5 rows of a table, df1 is your dataframe

df1.iloc[:5]

  1. Select first A, B rows of a table, df1 is your dataframe

df1.loc['A','B']

  • DataFrame.loc() : Select rows by index value
  • DataFrame.iloc() : Select rows by rows number

example :

  1. Select first 5 rows of a table, df1 is your dataframe

df1.iloc[:5]

  1. Select first A, B rows of a table, df1 is your dataframe

df1.loc['A','B']

Source Link
Nandini Ashok Tuptewar

DataFrame.loc() : Select rows by index value , DataFrame.iloc() : Select rows by rows number example :

  1. Select first 5 rows of a table, df1 is your dataframe

df1.iloc[:5]

  1. Select first A, B rows of a table, df1 is your dataframe

df1.loc['A','B']

lang-py