Warm tip: This article is reproduced from stackoverflow.com, please click
pandas python

i have multiple columns with the status of the areas,i need to get the status on status column if al

发布于 2020-03-29 12:48:31

I have multiple columns with the status of the areas, I need to get the status on status column if all the status are completed.

Table

Questioner
Deepweber
Viewed
16
jezrael 2020-01-31 19:22

You can filter all columns with Area in columns names by DataFrame.filter, compare by DataFrame.eq for == and test if all Trues per rows by DataFrame.all:

df['Status'] = df.filter(like='Area').eq('Completed').all(axis=1)

Or you can seelct all columns without first 2 by DataFrame.iloc:

df['Status'] = df.iloc[:, 2:].eq('Completed').all(axis=1)

Or last 3 columns:

df['Status'] = df.iloc[:, -3:].eq('Completed').all(axis=1)