0

I have this table for example:

Example Data

If your_pack_size is the same as competitor_pack_size, then your_measurement should not be the same as competitor_measurement

I would like to find the rows where this condition is broken (if any)

This is what I have tried already:

if (df_pr['your_pack_size'].any() == df_pr['competitor_pack_size'].any()):

  print('your_pack_size is the same as competitor_pack_size')

  print(df_pr.loc[df_pr['your_pack_size'].any() == df_pr['competitor_pack_size'].any()]['competitor_product_id'])

but I get an error. How can I print out the competitor_product_id where the condition is broken?

1 Answer 1

1
df[(df['your_pack_size'] == df['competitor_pack_size']) & (df['your_measurement'] == df['competitor_measurement'])]

i.e. get the rows where the sizes are the same AND the measurements are the same

See conditional selection in pandas, very handy to know https://www.includehelp.com/python/conditional-selection-in-the-dataframe-pandas-dataframe.aspx

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.