CommencerCommencer gratuitement

Selecting rows and columns

The syntax for subsetting both rows and columns in Pandas is similar to R. The rows and columns are specified to the left and right of the comma, respectively.

To subset rows and columns using boolean expressions or labels, you can use:

df.loc[row_labels, column_labels]

To subset rows and columns using indices, you can use:

df.iloc[row_indices, column_indices]

Cet exercice fait partie du cours

Python for R Users

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Subset rows and columns
print(tips.____[____, ____])
Modifier et exécuter le code