0

There is a pandas data frame. One of columns named Exceptions. Row represent entries. In Exceptions i store tuples.

i need to do a conditional selection of rows (there are other conditions which need to be &ed for further selection)

>>>print(dataframe.Exceptions)

0               
1               
2    (sfm, sfmp)
4               
3               
Name: Exceptions, dtype: object

>>>'sfm' not in dataframe.Expections
True

How to do this conditional selection with Tuples unpacked.

Appreciate your suggestions.

1
  • Could you display a few rows of your dataframe and specify the condition? Commented Jun 13, 2020 at 15:49

1 Answer 1

1

Here's an example showing how to get tuples that have 1 in the second position.

import pandas as pd

df = pd.DataFrame({
    'tups': [(0, 0), (0, 1), (0, 2), (1, 1)]
})

filtered = df[df['tups'].apply(lambda tup: tup[1] == 1)]
print(filtered)

Output:

     tups
1  (0, 1)
3  (1, 1)

Is this what you're looking for?

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

Comments

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.