Micaela De León
Micaela De León

Reputation: 75

print values of column 1 when values of another one are different from NaN

I'm sure this is easier than what I think, but I'm struggling. I have 3 columns,

1. Name: (a,b,c,d)

2. City/Birth: (w,x,y,z)

3. City/Current :(q,t,y,z)

I need to print the names of people when City/Birth is the same as City/Current.

Expected output: c,d

So far I applied lowercase, created a new column named "match" and I have like 300 "NaNs" and just "20" matches (where "Birth" and "current" are the same) with:

df['match'] = np.where((df['birth'] == df['current']), df['birth'], np.nan)

I'm just struggling to print the names of those 20 matches.

Upvotes: 0

Views: 37

Answers (1)

BENY
BENY

Reputation: 323226

You can just check .loc

df.loc[df['birth'] == df['current'],'Name']

Upvotes: 1

Related Questions