You can use DataFrame.loc
with specify condition and column name:
out = dfn.loc[dfn['No.'] == 'P1', 'Category']
Then out
is Series
, with one or more values, if no match get empty Series
.
If need first value of out
to scalar:
scalar = out.iat[0]
But this fail if empty Series:
out = dfn.loc[dfn['No.'] == 'aaaa', 'Category']
Then use:
scalar = next(iter(out), 'no match')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…