You can filter the rows of a DataFrame to only contain rows that meet some condition. For example, df[df.age >= 16] would return a new DataFrame with same columns and only the rows for which the age value was greater than or equal to 16.
Using the DataFrame
import pandas as pd df = pd.DataFrame({'name': ['Jeff', 'Esha', 'Jia'], 'age': [30, 56, 8]})
| name | age | |
|---|---|---|
| 1 | Jeff | 30 |
| 2 | Esha | 56 |
| 3 | Jia | 8 |
Write a function, only_names_that_start_with_j(df) which takes in the DataFrame and returns a new DataFrame with rows of names that start with 'J'.
Hint: the pandas .str functions would be helpful here.
df = pd.DataFrame({'name': ['Jeff', 'Esha', 'Jia'], 'age': [30, 56, 8]})
| name | age | |
|---|---|---|
| 0 | Jeff | 30 |
| 1 | Esha | 56 |
| 2 | Jia | 8 |
| name | age | |
|---|---|---|
| 0 | Jeff | 30 |
| 2 | Jia | 8 |