WeCodeAcademy

Selecting Columns and Rows

df['age'] gives one column (a Series). df[['name', 'age']] with a list gives a smaller DataFrame. For rows, df.loc[...] selects by label and df.iloc[...] selects by position.

Examplepython
Open in editor »
Quick check

What is the difference between `loc` and `iloc`?

Your turn: write the code

Print the name and city columns together.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.