Issue
Is there any way that I can drop the value if its index = column index.
I mean, this is my toy dataframe
d = {'Non': [1, 2,4,5,2,7], 'Schzerando': [3, 4,8,4,7,7], 'cc': [1,2,0.75,0.25,0.3,1]}
df = pd.DataFrame(data=d)
df
Then I just want to keep the row which df["cc"] == 1 and 2, like this
Toy dataframe to try.
Solution
You can filter out the rows by converting the cc
column to int type then filter by applying mask.
df['cc'] = df['cc'].astype('Int64')
df = df[df['cc'] == 1 | df['cc'] == 2 | df['cc'] == 3]
or you can declare a list with all the values you want to filter for then use pandas isin
f_list = [1,2,3]
df[df['cc'].isin(f_list)]
Answered By - Himanshu Poddar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.