![](/img/trans.png)
[英]pandas: get the exact corresponding value with the corresponding index based on a value in another column
[英]Get corresponding column value based on index in 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
...
日期的第一列是索引。 如何獲得index == 2012-04-21
和Data ==39
的對應Id
值,即1
? 我嘗試iloc
和loc
但我不確定如何處理索引。 謝謝。
讓我們試試
df.loc[(df.index=='2012-04-21') & (df.Data==39) ,'Id']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.