小编Ben*_*key的帖子

python - 基于列中的值重复行x次

我在酒店预订了大熊猫数据框.每行都是预订,如下所示:

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
Run Code Online (Sandbox Code Playgroud)

我想使用python进行转换,以便每行成为一个午夜.输出看起来像这样:

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
Run Code Online (Sandbox Code Playgroud)

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

python pandas

10
推荐指数
1
解决办法
4952
查看次数

pandas - 使用 for 循环将多列附加到数据帧

我想通过对 df2 中每个相关日期求和来填充空列“web”“mob”app“

df1:

id      start       end         web mob app
12345   2018-01-17  2018-01-20
12346   2018-01-19  2018-01-22
12347   2018-01-20  2018-01-23
12348   2018-01-20  2018-01-23
12349   2018-01-21  2018-01-24
Run Code Online (Sandbox Code Playgroud)

df2:

id      date        web mob app
12345   2018-01-17  7   17  10
12345   2018-01-18  9   18  7
12345   2018-01-19  3   19  15
12345   2018-01-20  6   17  8
12345   2018-01-21  8   9   13
12345   2018-01-22  4   15  12
12345   2018-01-23  8   11  13
12345   2018-01-24  9   16  14
12346   2018-01-17  3   17  12
12346   2018-01-18  4   19 …
Run Code Online (Sandbox Code Playgroud)

python for-loop numpy pandas

4
推荐指数
1
解决办法
3760
查看次数

标签 统计

pandas ×2

python ×2

for-loop ×1

numpy ×1