簡體   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