Label-Based Indexing (Loc) : DF - Loc (Row Label(s), Column Label(s) )

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Label-based Indexing (loc)

d f . l o c [r o w l a b e l (s ) , c o l u m n l a b e l (s ) ]

column labels

row labels
Label-based Indexing (loc) – Example 1

df.loc[“Neymar Junior”, “Club”]

Output is an element (“Paris SG”).


Label-based Indexing (loc) – Example 2

d f . l o c [ [ “ N e y m a r J u n i o r ” , “ Ky l i a n M b a p p e ” ] , “ C l u b ” :]

from column “Club” till last (inclusive)

Output is a DataFrame.
Label-based Indexing (loc) – Example 3
all columns

d f . l o c [ “ L i o n e l M e s s i ” : “ N e y m a r J u n i o r ” , :]

inclusive inclusive

Output is a DataFrame.
Label-based Indexing (loc) – Example 4

d f . l o c [: “ Ky l i a n M b a p p e ” , “ H e i g h t ” ]

from very first till “Kylian Mbappe” (inclusive)

Output is a Pandas Series.

You might also like