从pandas dataframe获取每个客户的最新数据

2024-09-25 00:25:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试获取每个客户的最新数据,而不考虑数据框中的其他属性

我的数据框看起来像这样

enter image description here

我的输出应该是这样的

My output should look like this

我尝试了'df.iloc[df.groupby('customer')['date'].idxmax()

“ValueError回溯(最近一次调用上次) 在里面 ---->;1 df=df.iloc[df.groupby('cutomer')['date'].idxmax()]

包装中的~\Anaconda3\envs\myenv\lib\site packages\pandas\core\groupby\groupby.py(*args,**kwargs) 653如果self.obj.ndim==1: 654#这可以递归调用,因此需要引发ValueError -->;655上升值错误 656 657#GH#3688试着逐项操作

值错误:“


Tags: 数据gtdfdate客户属性错误customer