[英]pandas DataFrame - how to get the duration of different players
I'm new to Python, and am analyzing bidding records using pandas. 我是Python新手,正在使用pandas分析出价记录。 I'd like to know the duration (time of last bid-time of first bid) of each players (7000 people), but I have no idea how to proceed.
我想知道每个玩家(7000人)的持续时间(首次竞标的最后竞标时间),但我不知道如何继续。 See below the data:
见下面的数据:
name bids profit date WeekOfYear
JEFF 3 -75 2012-05-25 21
JEFF 13 -325 2012-05-25 21
eQB 1 -25 2012-05-25 21
eQB 1 -25 2012-07-02 27
eQB 1 -25 2012-07-09 28
alianx 7 -175 2012-05-25 21
alianx 19 -475 2012-05-25 21
alianx 59 -1475 2012-05-26 21
alianx 13 -325 2012-05-26 21
alianx 7 -175 2012-05-27 21
Data columns (total 5 columns):
name_x 95640 non-null object
date 95640 non-null datetime64[ns]
Expected results: 预期成绩:
name duration first_time last_time
JEFF 1 2012-05-25 2012-05-25
eQB 46 2012-05-25 2012-07-09
alianx 3 2012-05-25 2012-05-27
I'm having trouble calculating the first_time and last_time of each player, once tried: 一旦尝试过,我在计算每个玩家的first_time和last_time时遇到问题:
data['last_time'] = data.groupby(['date','name_x']).max().reset_index()
But it seems not working. 但它似乎不起作用。 Thanks in advance!
提前致谢!
I am not sure about your data based on what you proposed above (ie I didn't see name_x
in the dataframe, but assume it must be there). 我不确定你的数据是基于你上面的建议(即我没有在数据
name_x
看到name_x
,但假设它必须在那里)。 I would try: 我会尝试:
data['last_time'] = data.groupby(['name_x'])['date'].transform('max')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.