1. Learn
  2. /
  3. Courses
  4. /
  5. Python for R Users

Exercise

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]

Instructions 1/2

undefined XP
    1
    2

Subset all the rows where sex is 'Female' while retaining only the total_bill, tip, and sex columns, in that order.