loc do in pandas?loc selects data by label. It uses the row and column names you see in the DataFrame.
iloc do in pandas?iloc selects data by position. It uses the row and column numbers starting from 0.
[10, 20, 30], what will df.loc[20] return?It returns the row with label 20. Labels are exact matches.
df.iloc[2] return?It returns the third row (index 2) because iloc counts rows by position starting at 0.
loc and iloc?loc slices include the end label (inclusive). iloc slices exclude the end position (like normal Python slices).
loc uses labels. iloc uses positions.
df.iloc[0] return?iloc selects by position, so 0 means the first row.
[1, 3, 5], what does df.loc[3] return?loc uses labels, so it returns the row labeled 3.
loc slices include the end label; iloc slices exclude the end position.
df.iloc[5] on a DataFrame with 5 rows?iloc uses zero-based positions. Index 5 is out of range for 5 rows, so it raises an error.
loc and iloc in pandas using a real-life example.loc and iloc.