[英]Time Series Analysis to find a particular date based on conditions
I have the following dataframe badges
.我有以下 dataframe
badges
。 The Class
column has the level of the badge (1=Gold, 2=Silver, 3=Bronze)
. Class
列具有徽章级别(1=Gold, 2=Silver, 3=Bronze)
。 I want to get the time when the user with UserId = '699'
got his first silver medal.我想知道
UserId = '699'
的用户获得第一枚银牌的时间。 I tried the given code but I am getting a KeyError.我尝试了给定的代码,但我得到了一个 KeyError。 Please help me fix this.
请帮我解决这个问题。
DataFrame 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
Code代码
test_silver = badges[badges.Date.loc[badges.UserId=='699']]
min(test_silver)
You can use boolean indexing (like you already did) and then head
to extract the first record:您可以使用 boolean 索引(就像您已经做过的那样)然后
head
提取第一条记录:
badges.loc[badges.UserId.eq('699') & badges.Class.eq(2), 'Date'].head(1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.