簡體   English   中英

時間序列分析,根據條件查找特定日期

[英]Time Series Analysis to find a particular date based on conditions

我有以下 dataframe badges Class列具有徽章級別(1=Gold, 2=Silver, 3=Bronze) 我想知道UserId = '699'的用戶獲得第一枚銀牌的時間。 我嘗試了給定的代碼,但我得到了一個 KeyError。 請幫我解決這個問題。

DataFrame

   Id | UserId |  Name          |        Date              |Class | TagBased
   2  | 23     | Autobiographer | 2016-01-12T18:44:49.267  |   3  | False
   3  | 22     | Autobiographer | 2016-01-12T18:44:49.267  |   3  | False
   4  | 21     | Autobiographer | 2016-01-12T18:44:49.267  |   3  | False
   5  | 20     | Autobiographer | 2016-01-12T18:44:49.267  |   3  | False
   6  | 19     | Autobiographer | 2016-01-12T18:44:49.267  |   3  | False

代碼

test_silver = badges[badges.Date.loc[badges.UserId=='699']]
min(test_silver)

您可以使用 boolean 索引(就像您已經做過的那樣)然后head提取第一條記錄:

badges.loc[badges.UserId.eq('699') & badges.Class.eq(2), 'Date'].head(1)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM