I am trying to select a subset from a single dataframe column, and I need help applying two conditions on a single column. For example, how do I select for both "Tom" and "Chris" in the table below?
import pandas as pd
dic={"Name":["Chris","Tom","Steven"], "Age":[12,34,55]}
dic={"Name":["Chris","Tom","Steven"], "Age":[12,34,55]}
df=pd.DataFrame(dic)
df[df["Name"]=="Tom"]
Why is it that when I use
df[df["Name"]==("Chris" or "Tom")]
it picks "Chris, but when or is replaced by and, "Tom" is selected?
"Chris" or "Tom"which is a pretty bizarre operation. Python has 'truthiness' for strings. Any non-empty string evaluates asTrue. Follow MaxU's explanation for the rest.