I tried multiple ways. I have below data frame and I have EMP ID from other process. I want to find EMP name based on EMP ID.
EMP ID Name EMP Location 1 John A New York 2 Paul London 3 Adam K London 4 Lawrence L London below code in not working emp_name= df['EMP ID']==id_no print(emp_name[Name Emp])
I want Name – Paul for EMP ID =2
Am I passing EMP ID right in data frame? I tried df.query also. Am I doing something wrong?
df["EMP ID"]==id_no, you will get a series of boolean which represents a result of elementwise comparison:
df["EMP ID"] == 2 0 False 1 True 2 False 3 False Name: EMP ID, dtype: bool
EMP ID is unique for each
Name EMP, you can make a new series that can act as a dict:
s = df.set_index("EMP ID")["Name EMP"] s[id_no]