I have a dataframe like the one below having 3 types of status -'complete','start' and 'fail'. I want to create another dataframe from this keeping only the "fail" status entries with their corresponding level number.
Python: Create seperate dataframe from a dataframe with one category of the category variable column
Asked
Active
Viewed 180 times
1 Answers
1
Let's do this:
fail_df = df[df['status']=='fail']
or this with str.contains
:
fail_df = df[df['status'].str.contains(r'fail',case=False)]
Both ways will give a new dataframe
with only status being 'fail'. However, the str.contains
method is more robust to typo's.

sophocles
- 13,593
- 3
- 14
- 33