繁体   English   中英

尝试通过匹配行值来 select 列,但返回该列中另一行的值

[英]Trying to select a column by matching a row value but return the value of another row in that column

我有一个 pandas dataframe

       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”值

如果 select 可以使用该列

c = df.loc['id'] = 1

现在我尝试获取dosnt工作的列'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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM