|
175 | 175 | }, |
176 | 176 | { |
177 | 177 | "cell_type": "code", |
178 | | - "execution_count": 20, |
| 178 | + "execution_count": null, |
179 | 179 | "id": "5f14f38c", |
180 | 180 | "metadata": {}, |
181 | 181 | "outputs": [ |
|
198 | 198 | "model_csv.dc = DataCollector(\n", |
199 | 199 | " model=model_csv,\n", |
200 | 200 | " model_reporters={\n", |
201 | | - " \"total_wealth\": lambda m: list(m.sets.df.values())[0][\"wealth\"].sum(),\n", |
202 | | - " \"n_agents\": lambda m: len(list(m.sets.df.values())[0]),\n", |
| 201 | + " \"total_wealth\": lambda m: sum(\n", |
| 202 | + " s[\"wealth\"].sum() for s in m.sets if \"wealth\" in s.df.columns\n", |
| 203 | + " ),\n", |
| 204 | + " \"n_agents\": lambda m: len(m.sets.ids),\n", |
203 | 205 | " },\n", |
204 | 206 | " agent_reporters={\n", |
205 | 207 | " \"wealth\": \"wealth\",\n", |
|
226 | 228 | }, |
227 | 229 | { |
228 | 230 | "cell_type": "code", |
229 | | - "execution_count": 21, |
| 231 | + "execution_count": null, |
230 | 232 | "id": "8763a12b2bbd4a93a75aff182afb95dc", |
231 | 233 | "metadata": { |
232 | 234 | "editable": true |
|
249 | 251 | "model_parq.dc = DataCollector(\n", |
250 | 252 | " model=model_parq,\n", |
251 | 253 | " model_reporters={\n", |
252 | | - " \"total_wealth\": lambda m: list(m.sets.df.values())[0][\"wealth\"].sum(),\n", |
253 | | - " \"n_agents\": lambda m: len(list(m.sets.df.values())[0]),\n", |
| 254 | + " \"total_wealth\": lambda m: sum(\n", |
| 255 | + " s[\"wealth\"].sum() for s in m.sets if \"wealth\" in s.df.columns\n", |
| 256 | + " ),\n", |
| 257 | + " \"n_agents\": lambda m: len(m.sets.ids),\n", |
254 | 258 | " },\n", |
255 | 259 | " agent_reporters={\n", |
256 | 260 | " \"wealth\": \"wealth\",\n", |
|
279 | 283 | }, |
280 | 284 | { |
281 | 285 | "cell_type": "code", |
282 | | - "execution_count": 22, |
| 286 | + "execution_count": null, |
283 | 287 | "id": "7cdc8c89c7104fffa095e18ddfef8986", |
284 | 288 | "metadata": { |
285 | 289 | "editable": true |
|
289 | 293 | "model_s3 = MoneyModel(1000)\n", |
290 | 294 | "model_s3.dc = DataCollector(\n", |
291 | 295 | " model=model_s3,\n", |
292 | | - " model_reporters={\n", |
| 296 | + " model_reporters = {\n", |
| 297 | + "\"total_wealth\": lambda m: sum(\n", |
| 298 | + "s[\"wealth\"].sum() for s in m.sets if \"wealth\" in s.df.columns\n", |
| 299 | + "),\n", |
| 300 | + "\"n_agents\": lambda m: len(m.sets.ids),\n", |
| 301 | + "}\n", |
| 302 | + "\n", |
| 303 | + "\n", |
293 | 304 | " \"total_wealth\": lambda m: list(m.sets.df.values())[0][\"wealth\"].sum(),\n", |
294 | 305 | " \"n_agents\": lambda m: len(list(m.sets.df.values())[0]),\n", |
295 | 306 | " },\n", |
|
0 commit comments