0

Say there's a data frame with (4000,13) shape. Say dataframe["str_labels"] may has "|" value in it. How to sort pandas dataframe based on removing any rows (all 13 columns) consisting of string value "|". example:

list(dataframe["str_labels"])=["abcd","aaa","op|gg","iku | gv"]
filtered_out = ["abcd", "aaa"]
## example code
dataframe["|" not in dataframe["str_labels"]]
# or
dataframe[dataframe["str_Labels"].str.contains("|")]
# ........etc
2

1 Answer 1

2

You should make a list of characters that are the conditions for dropping rows:

list = ['<character>', '\|',....]

and then filter your df by

df = df[~df['your column'].isin(['list'])]

Note the \| for the pipe character.

Sign up to request clarification or add additional context in comments.

2 Comments

For any other string it's working but not for "|". why so?
Sorry for the typo. For pipe character | you need in your list to give ´\|'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.