回答編集履歴
1
追加
answer
CHANGED
@@ -17,6 +17,36 @@
|
|
17
17
|
|
18
18
|
そのため、df_pool.sum()で記載のエラーが出ています。
|
19
19
|
|
20
|
+
今回の場合、中で使うデータを削っていくようなやり方はわかりにくくなるのではないでしょうか。
|
21
|
+
条件に合致するしないのブールのSeries(下記の`select`)をandやorで更新していって、最後にデータを取り出すのが良いように思います。
|
22
|
+
|
23
|
+
```python
|
24
|
+
for agent in agent_dict.keys():
|
25
|
+
data = df[df["ReservationRouteCode1"] == agent]
|
26
|
+
if len(data) == 0:
|
27
|
+
continue
|
28
|
+
|
29
|
+
result = []
|
30
|
+
for j in package_dict.values():
|
31
|
+
package_code = j[0]
|
32
|
+
room_type1 = j[1]
|
33
|
+
room_type2 = j[2]
|
34
|
+
people = j[3]
|
35
|
+
|
36
|
+
select = (data["PackageCode"] == package_code)
|
37
|
+
if people is not None:
|
38
|
+
select &= (data["PersonsPerRoom"] == people)
|
39
|
+
if room_type1 is not None:
|
40
|
+
room = (data["RoomType"] == room_type1)
|
41
|
+
if room_type2 is not None:
|
42
|
+
room |= (data["RoomType"] == room_type2)
|
43
|
+
select &= room
|
44
|
+
result.append(data[select])
|
45
|
+
df_result = pd.concat(result)
|
46
|
+
print(agent, df_result['ResultPerson'].sum())
|
47
|
+
```
|
48
|
+
|
49
|
+
|
20
50
|
> 最終的に求めたいのが仕分けた後に残ったdataframeのResultpersonの合計なのでそのようにしました!
|
21
51
|
|
22
52
|
やりたいことを完全には理解できていないので、違うかもしれませんが、合計を求めるのは内側のループが全部終わってからやればいいのではないですか?
|