Skip to content

Commit 9e3eb1d

Browse files
committed
adding pandas solution as a reference to the 'means of subsets' exercise
1 parent 497f204 commit 9e3eb1d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

100 Numpy exercises.ipynb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,11 @@
14671467
"D_sums = np.bincount(S, weights=D)\n",
14681468
"D_counts = np.bincount(S)\n",
14691469
"D_means = D_sums / D_counts\n",
1470-
"print(D_means)"
1470+
"print(D_means)\n",
1471+
"\n",
1472+
"# Pandas solution as a reference due to more intuitive code\n",
1473+
"import pandas as pd\n",
1474+
"print(pd.Series(D).groupby(S).mean())"
14711475
]
14721476
},
14731477
{

100 Numpy exercises.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,10 @@ D_sums = np.bincount(S, weights=D)
714714
D_counts = np.bincount(S)
715715
D_means = D_sums / D_counts
716716
print(D_means)
717+
718+
# Pandas solution as a reference due to more intuitive code
719+
import pandas as pd
720+
print(pd.Series(D).groupby(S).mean())
717721
```
718722

719723
#### 69. How to get the diagonal of a dot product? (★★★)

0 commit comments

Comments
 (0)