How To Match Multiple Columns And Find Specific Column Value In Pandas?
I have below dataframe in Pandas. It stored in df that works similar to this: +--------+--------+-------+ | Col1 | Col2 | Col3 | +--------+--------+-------+ | Team 1 | High
Solution 1:
Use &
for bitwise AND
- solution working if always data matched:
result = df.loc[(df['Col1'] =='Team2') & (df['Col2']=='Medium'), 'Col3'].values[0]
Another solution with next
and iter
for return default value, if no match data:
s = df.loc[(df['Col1'] =='Team2') & (df['Col2']=='Medium'), 'Col3']
result = next(iter(s, 'no matching')
Post a Comment for "How To Match Multiple Columns And Find Specific Column Value In Pandas?"