尝试 select 通过匹配行值来匹配列,但 return 该列中另一行的值
Trying to select a column by matching a row value but return the value of another row in that column
我有一个 pandas 数据框
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 和 return 相同列 'mac' 值
如果可以select列
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
我有一个 pandas 数据框
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 和 return 相同列 'mac' 值
如果可以select列
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