根据熊猫索引获取相应的列值

时间:2020-06-16 01:47:17

标签: python pandas

我有df

            Id          Timestamp               Data    Id      Day
2012-04-21  19389576    2012-04-21 00:04:03.533 39.0    1       2012-04-21
2012-04-21  19389577    2012-04-21 00:04:04.870 38.5    1       2012-04-21
2012-04-21  19389608    2012-04-21 00:07:03.450 38.0    1       2012-04-21
2012-04-22  19389609    2012-04-21 00:03:04.817 37.5    2       2012-04-21
2012-04-22  19389620    2012-04-21 00:10:04.400 37.0    2       2012-04-21
                        ...

日期的第一列是索引。如何获得相应的Id值,其中index == 2012-04-21Data ==39,即1?我尝试了ilocloc,但不确定如何处理索引。谢谢。

1 个答案:

答案 0 :(得分:1)

让我们尝试

df.loc[(df.index=='2012-04-21') & (df.Data==39) ,'Id']