我有一个这样的数据集
event_date | user_id | user_city | user_state |
06-09-2021 | 23 | Thane | Maharashtra
04-09-2021 | 3224 | Madurai | Tamil Nadu
02-08-2021 | 2331 | Ghaziabad | Utter Pradesh
使用python,我希望以这种格式输出
User ID | Date of | Location of | Location of | Location on Second |
| Last Logins | Latest Login | Max Logins | Most Login |
| | | | |
5 | 11-09-2021 | Gurgaon | Meerut | Noida |
您可以尝试使用^{} 和^{} ,并在使用新列名应用^{} 后返回^{}
方法2
使用^{} 获取最大日期,而无需对数据帧进行排序(即,可以避免使用
df.sort_values('event_date')
)注意:在某些情况下,sort_值会更快,以避免每次迭代中访问nlargest的开销
如果我的代码不符合您的预期结果,请通知我
相关问题 更多 >
编程相关推荐