| 6 | |
| 7 | |
| 8 | def weighted_row_sum(data, third_rows, weight_col=1, start_col=2): |
| 9 | |
| 10 | data = np.array(data) |
| 11 | m,n = data.shape |
| 12 | rows = slice(m-third_rows, m) |
| 13 | cols = slice(start_col, None) |
| 14 | weighted_sum = np.sum(data[rows, cols].astype(float) * data[rows, weight_col].astype(float)[:, np.newaxis], axis=0) / np.sum(data[rows, weight_col].astype(float)) |
| 15 | weighted_sum = ['Mean',np.sum(data[rows, weight_col].astype(float))] + weighted_sum.tolist() |
| 16 | temp = data.tolist() |
| 17 | temp.append(weighted_sum) |
| 18 | return temp |
| 19 | |
| 20 | |
| 21 | |