我有一个熊猫数据框架
field sev iso des
0 shortname sev iso des
1 fullname Sevoflurane Isoflurane Desflurane
2 id 0 1 2
3 colorname Gold Dark Magenta Royal Blue
4 colorHex #FFD700 #8B008B #4169E1
5 mac 2.1 1.15 5.8
我试图找到正确的pandas语法来搜索 "id "行与值1匹配的列,并返回相同列的 "mac "值。
如果可以选择带有
c = df.loc['id'] = 1
现在我试图获取列 "mac "的值,但没有成功。
_mac = csv_rx_df.at[c, 'mac']
我怎么做呢?
#set 'field' as index
df = df.set_index('field')
#get the column where id row equals "1", and subsequently,
#get the value for 'mac'
df.loc['mac',df.loc['id',:].eq("1")]
iso 1.15
Name: mac, dtype: object