I am kind of getting stuck on extracting value of one variable conditioning on another variable. For example, the following dataframe:
A B
p1 1
p1 2
p3 3
p2 4
How can I get the value of A
when B=3
? Every time when I extracted the value of A
, I got an object, not a string.
item()
at the end. - Gejundf.query
andpd.eval
seem like good fits for this use case. For information on thepd.eval()
family of functions, their features and use cases, please visit Dynamic Expression Evaluation in pandas using pd.eval(). - cs95