python根据列中的值重复行x次

2024-04-26 10:50:04 发布

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

我有一个熊猫数据框在一家酒店预订。每一行都是预订,如下所示:

Name             Arrival       Departure     RoomNights
Trent Cotchin    29/10/2017    2/11/2017     4
Dustin Martin    1/11/2017     4/11/2017     3
Alex Rance       2/11/2017     3/11/2017     1

我想使用python来转换,这样每一行就变成一个roomnight。输出如下:

Name             Arrival       Departure     RoomNights   RoomNight Date
Trent Cotchin    29/10/2017    2/11/2017     4            29/10/2017
Trent Cotchin    29/10/2017    2/11/2017     4            30/10/2017
Trent Cotchin    29/10/2017    2/11/2017     4            31/10/2017
Trent Cotchin    29/10/2017    2/11/2017     4            1/11/2017
Dustin Martin    1/11/2017     4/11/2017     3            1/11/2017
Dustin Martin    1/11/2017     4/11/2017     3            2/11/2017
Dustin Martin    1/11/2017     4/11/2017     3            3/11/2017
Alex Rance       2/11/2017     3/11/2017     1            2/11/2017

这使我可以轻松地计算出任何给定日/月的总房间夜数。


Tags: 数据namedate酒店martinalexdeparturearrival