【发布时间】:2019-08-28 06:54:48
【问题描述】:
所以我有一小部分数据,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,所以我试图找到一种方法从这个输出中提取它。
感谢您的帮助。
【问题讨论】:
-
@Chris 下面的答案是最好的,但你也可以添加....TFR[filt]['State3'].values[0]
-
@run-out 非常感谢,成功了!克里斯的回答也有效,但我还没有达到我遇到这些功能的水平,因为我现在只是一个初学者!
标签: python python-3.x pandas dataframe jupyter-notebook