使用pandas dataFrame中的Groupby日期创建列表列表
df =
Date Slot
0 2022-02-23 34
1 2022-02-23 35
2 2022-02-24 0
3 2022-02-24 1
4 2022-02-25 0
5 2022-02-25 1
这是我的df,我想要一个具有相同相应的“日期”值的所有“插槽”值的列表,即我的输出应该看起来像[[34,35],[0,1],[0,1],[0,[0, 1]]
ps:日期列中的值未经事先知道,因此在这里没有进行硬编码,是否有一般性执行此任务的概括。
df =
Date Slot
0 2022-02-23 34
1 2022-02-23 35
2 2022-02-24 0
3 2022-02-24 1
4 2022-02-25 0
5 2022-02-25 1
This is my df and I want a list of lists for all the 'Slot' values having the same corresponding 'Date' value i.e my output should look like [[34,35] , [0,1] , [0,1]]
PS: The values in the date column are not known beforehand so hardcoding is not working out here, is there a generalized to do this task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试
You can try