Python 熊猫-基于a列中的值访问B列中的值

Python 熊猫-基于a列中的值访问B列中的值,python,python-3.x,pandas,dataframe,jupyter-notebook,Python,Python 3.x,Pandas,Dataframe,Jupyter Notebook,因此,我有一小部分数据,TFR.csv采用以下形式: Year State1 State2 State3 1993 3 4 5 1994 6 2 1.4 ... 我应该确定2号州的价值何时处于最低水平(1994年),并提取3号州在那一年的价值(1.4) 为此,我编写了一个简短的过滤器: State1Min = min(TFR['State1']) #Determine t

因此,我有一小部分数据,
TFR.csv
采用以下形式:

Year     State1     State2     State3
1993       3          4           5
1994       6          2           1.4
...
我应该确定2号州的价值何时处于最低水平(1994年),并提取3号州在那一年的价值(1.4)

为此,我编写了一个简短的过滤器:

State1Min = min(TFR['State1']) #Determine the minimum value for State1

filt = (TFR['State1']==State1Min) #Filter to select the row where the value exists

TFR[filt]['State3'] #Apply this filter to the original table, and return the value in the State3 column.
它返回我要查找的正确值,但也返回前面的行号:

2     1.4
Name: NT, dtype: float64
我需要打印这个值1.4,所以我试图找到一种方法从输出中提取它


感谢您的帮助。

使用
pandas.DataFrame.set\u index
idxmin

df = df.set_index('Year')
df.loc[df['State2'].idxmin(), 'State3']
输出:

1.4

@Chris下面的答案是最好的,但您也可以添加…TFR[filt]['State3']。值[0]@run out谢谢您,成功了!Chris的答案也很有效,但我还没有达到那个水平,因为我还只是一个初学者!非常感谢!最后我在一篇评论中使用了上面列出的一种方法,因为这更符合我的速度,因为我只是一个初学者,但你给了我一些如何继续学习这门语言的指导。