I have a df with 2 columns and 3 rows
is_active group_name
0 True group_one
1 True specific_string
2 True group_one
first I checked with if the df contains a specific value in a columns
df['group_name'].str.contains("specific_string").any()
now I wanto to check if the value on the same row but on the other column is == is_active
I want to get boolean as return, the second line doesnt work
if df['group_name'].str.contains("specific_string").any():
df.loc[df['group_name'].str.contains('specific_string').any(), 'is_active']
return True
In second row is used boolean indexing
, so any
is removed:
out = df.loc[df['group_name'].str.contains('specific_string'), 'is_active']
Then select first matched value by indexing:
return out.iat[0]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.