'how to check a Dictionary key particular row value in python
Here is my Dictionary:
dict = {'UID1': USER ID Table EMAIL
user1 tbl1 abc
user1 tbl2 abc
user1 tbl3 abc
'UID2': USER ID Table EMAIL
user2 tbl4 efg
user2 tbl5 efg
user2 tbl6 efg}
I would like to iterate over dictionary and fetch Email column first value as abc
for key in dict:
mgr = dict[key]['EMAIL'][1]
print(mgr)
This code gives error: pls help to fetch the correct value.
Solution 1:[1]
Pandas count from 0, so for first value by position use Series.iat with 0:
for key, val in dict.items():
mgr = val['EMAIL'].iat[0]
print(mgr)
Or is possible use DataFrame.iat with position of column EMAIL by Index.get_loc:
for key, val in dict.items():
mgr = val.iat[0, val.columns.get_loc('EMAIL')]
print(mgr)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jezrael |
