Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 3 找到顾客第一次购买行为的时间 #4

Open
DanielWZH opened this issue Nov 17, 2023 · 1 comment
Open

Chapter 3 找到顾客第一次购买行为的时间 #4

DanielWZH opened this issue Nov 17, 2023 · 1 comment

Comments

@DanielWZH
Copy link

2021年到2023年可能Pandas版本几经变更, 导致DataFrame的聚合操作 出现Keyerror : CustomerID, 我调整了一下Code的顺序
data1=data0.assign(amount=data0['UnitPrice'].multiply(data0['Quantity'])) first_time=data1[['CustomerID','InvoiceDate']].groupby('CustomerID').nth(0).reset_index().rename(columns={'InvoiceDate':'first_time'}) first_time['first_time'] = first_time['first_time'].apply(lambda x: x.date()) data2=pd.merge(data1,first_time,how='left',on=['CustomerID'])
应该是可以正常运行了
另外Chapter 3 还有多处 Load Data 指定的数据文件路径一会儿在 Data 子文件夹里, 一会儿又是同级文件夹, 看得人头发晕😂

@xieliaing
Copy link
Owner

数据文件路径这点已经反馈给作者。这是行业里面数据科学家缺乏软件开发背景的一个问题,在代码的复用性上和严谨性上关注不够。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants