Filtering column value based on unique value, but not repeated for different value of the same column on the same unique value

Mick

Looking for ways to filter unique values with inactive status, but not repeated as active status under the same unique value.

df:

Unique_value    Status
1               Active        <- Has both active and inactive, must be inactive only
1               Active        <- Has both active and inactive, must be inactive only
1               Inactive      <- Has both active and inactive, must be inactive only
1               Inactive      <- Has both active and inactive, must be inactive only
2               Inactive      <- Has inactive only
2               Inactive      <- Has inactive only
2               Inactive      <- Has inactive only
3               Inactive      <- Has inactive only (cancelled okay to be filtered out)
3               Cancelled     <- Has inactive only (cancelled okay to be filtered out)
3               Inactive      <- Has inactive only (cancelled okay to be filtered out)

Desired output:

Unique_value    status
2               Inactive
3               Inactive

What I tried so far, but I don't think this is correct.

p = ['Inactive', 'Active']
df.groupby('Unique_value')['Status'].apply(lambda x: (x =='Inactive') != set(p))
Erfan

First check if any of the values in each group are Active or Inactive. Then get rid of the groups where both conditions are true:

m1 = df["Status"].eq("Active").groupby(df["Unique_value"]).transform("any")
m2 = df["Status"].eq("Inactive").groupby(df["Unique_value"]).transform("any")
df[~(m1 & m2)].groupby("Unique_value", as_index=False).first()

   Unique_value    Status
0             2  Inactive
1             3  Inactive

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

r - Replace values in a data.frame column with a different value in the same column based unique ID

From Dev

unique value based on another column value?

From Dev

Add a unique identifier to the same column value in R data frame

From Dev

Check for same value we have same unique value in other column in R

From Dev

Excel summing values based on value of different column in same row

From Dev

select a row based on different column value (same row)

From Dev

Vectorized calculation of a column's value based on a previous value of the same column?

From Dev

assign a unique ID number for every repeated value in a column R

From Dev

increment if not same value of column

From Dev

Ensure unique value for column in QTableView

From Dev

unique column value per row

From Dev

how to compare the value in the same table in a different column

From Dev

Increment column value in mysql based on same ID

From Dev

For a unique specified value in table column 2, how do I click column 8 in the same row?

From Dev

How to find column values which contains unique value in another column from same dataframe?

From Dev

mysql - Select unique column based on max value of another column in a different table

From Java

Calculate value based on value from same column of the previous row in spark

From Dev

PHP CSV check value in column and loop based if value is the same

From Dev

Concat Same Name different Value JSON object into unique one

From Dev

Update value in a column based on another column in the same table in MYSQL

From Dev

DAX for populating column value based on previous row of same column

From Dev

Adding multiple cells in a column based on a value in another column but same rows

From Dev

Replace a row in a pandas DataFrame with a dict item based on a unique column value

From Dev

Return unique row when using GROUP BY based on a column value

From Dev

Selecting 1 record based on last unique value that is on another column

From Dev

Select latest value of another column based on a comparison between unique keys

From Dev

How to group SQL Value if the column is same value

From Dev

SQL- Change column value based on other column values in same group & different row

From Dev

Add specific column value for first unique value in other column in R

Related Related

  1. 1

    r - Replace values in a data.frame column with a different value in the same column based unique ID

  2. 2

    unique value based on another column value?

  3. 3

    Add a unique identifier to the same column value in R data frame

  4. 4

    Check for same value we have same unique value in other column in R

  5. 5

    Excel summing values based on value of different column in same row

  6. 6

    select a row based on different column value (same row)

  7. 7

    Vectorized calculation of a column's value based on a previous value of the same column?

  8. 8

    assign a unique ID number for every repeated value in a column R

  9. 9

    increment if not same value of column

  10. 10

    Ensure unique value for column in QTableView

  11. 11

    unique column value per row

  12. 12

    how to compare the value in the same table in a different column

  13. 13

    Increment column value in mysql based on same ID

  14. 14

    For a unique specified value in table column 2, how do I click column 8 in the same row?

  15. 15

    How to find column values which contains unique value in another column from same dataframe?

  16. 16

    mysql - Select unique column based on max value of another column in a different table

  17. 17

    Calculate value based on value from same column of the previous row in spark

  18. 18

    PHP CSV check value in column and loop based if value is the same

  19. 19

    Concat Same Name different Value JSON object into unique one

  20. 20

    Update value in a column based on another column in the same table in MYSQL

  21. 21

    DAX for populating column value based on previous row of same column

  22. 22

    Adding multiple cells in a column based on a value in another column but same rows

  23. 23

    Replace a row in a pandas DataFrame with a dict item based on a unique column value

  24. 24

    Return unique row when using GROUP BY based on a column value

  25. 25

    Selecting 1 record based on last unique value that is on another column

  26. 26

    Select latest value of another column based on a comparison between unique keys

  27. 27

    How to group SQL Value if the column is same value

  28. 28

    SQL- Change column value based on other column values in same group & different row

  29. 29

    Add specific column value for first unique value in other column in R

HotTag

Archive