How do loc and iloc differ in pandas?
-
A
loc works only on Series objects
-
B
iloc works only on numeric columns
-
C
loc uses labels; iloc uses positions
Correct answer
-
D
loc uses positions; iloc uses labels
Correct answer
C. loc uses labels; iloc uses positions
12 views
Explanation
loc indexes by label, with inclusive slice endpoints, whereas iloc indexes by integer position.
Reference
Asked in: NTS, PPSC IT, Interviews
Doubts & discussion
Not sure why the answer is C? Ask here and get an explanation.
Ask a doubt about this MCQ