Issue
I have a dataframe in pandas with columns QUESTIONS and ANSWERS
| QUESTION | ANSWER |
| -------- | ------ |
| www | 123 |
| aaa | 3546 |
| vvv | 432 |
| ttt | 455 |
| QUESTION | 534 |
| eee | 4344 |
| yyy | 5435 |
I need to delete a row = 'QUESTIONS' in column QUESTIONS I do it this 2 ways but it deletes the whole column
# 1 approach
test_df = test_df.drop("QUESTIONS", axis=1)
# 2 approach
test_df = test_df.set_index("QUESTIONS")
test_df = test_df.drop("QUESTIONS", axis=0) # Delete all rows with label
What is my mistake that it deletes the whole column?
Solution
Use the loc
operator
test_df = test_df.loc[~(test_df.QUESTION=='QUESTION')]
Answered By - Arnau
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.