回答編集履歴
1
追加
test
CHANGED
@@ -36,6 +36,66 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
+
今回の場合、中で使うデータを削っていくようなやり方はわかりにくくなるのではないでしょうか。
|
40
|
+
|
41
|
+
条件に合致するしないのブールのSeries(下記の`select`)をandやorで更新していって、最後にデータを取り出すのが良いように思います。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```python
|
46
|
+
|
47
|
+
for agent in agent_dict.keys():
|
48
|
+
|
49
|
+
data = df[df["ReservationRouteCode1"] == agent]
|
50
|
+
|
51
|
+
if len(data) == 0:
|
52
|
+
|
53
|
+
continue
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
result = []
|
58
|
+
|
59
|
+
for j in package_dict.values():
|
60
|
+
|
61
|
+
package_code = j[0]
|
62
|
+
|
63
|
+
room_type1 = j[1]
|
64
|
+
|
65
|
+
room_type2 = j[2]
|
66
|
+
|
67
|
+
people = j[3]
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
select = (data["PackageCode"] == package_code)
|
72
|
+
|
73
|
+
if people is not None:
|
74
|
+
|
75
|
+
select &= (data["PersonsPerRoom"] == people)
|
76
|
+
|
77
|
+
if room_type1 is not None:
|
78
|
+
|
79
|
+
room = (data["RoomType"] == room_type1)
|
80
|
+
|
81
|
+
if room_type2 is not None:
|
82
|
+
|
83
|
+
room |= (data["RoomType"] == room_type2)
|
84
|
+
|
85
|
+
select &= room
|
86
|
+
|
87
|
+
result.append(data[select])
|
88
|
+
|
89
|
+
df_result = pd.concat(result)
|
90
|
+
|
91
|
+
print(agent, df_result['ResultPerson'].sum())
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
39
99
|
> 最終的に求めたいのが仕分けた後に残ったdataframeのResultpersonの合計なのでそのようにしました!
|
40
100
|
|
41
101
|
|