回答編集履歴
2
掛け算を追加
test
CHANGED
@@ -83,3 +83,47 @@
|
|
83
83
|
>>>
|
84
84
|
|
85
85
|
```
|
86
|
+
|
87
|
+
掛け算なら以下です。
|
88
|
+
|
89
|
+
```python
|
90
|
+
|
91
|
+
>>> import functools
|
92
|
+
|
93
|
+
>>> import operator
|
94
|
+
|
95
|
+
>>>
|
96
|
+
|
97
|
+
>>> print(df)
|
98
|
+
|
99
|
+
C1 C2 C3
|
100
|
+
|
101
|
+
0 24 24 31
|
102
|
+
|
103
|
+
1 18 38 24
|
104
|
+
|
105
|
+
2 19 11 15
|
106
|
+
|
107
|
+
3 35 18 21
|
108
|
+
|
109
|
+
>>>
|
110
|
+
|
111
|
+
>>> def pi_cn(df, column, n):
|
112
|
+
|
113
|
+
... return functools.reduce(operator.mul, df[column].values[:n], 1)
|
114
|
+
|
115
|
+
...
|
116
|
+
|
117
|
+
>>> print(pi_cn(df, 'C2', 2))
|
118
|
+
|
119
|
+
912
|
120
|
+
|
121
|
+
>>> print(pi_cn(df, 'C2', 3))
|
122
|
+
|
123
|
+
10032
|
124
|
+
|
125
|
+
>>> print(pi_cn(df, 'C2', 4))
|
126
|
+
|
127
|
+
180576
|
128
|
+
|
129
|
+
```
|
1
任意の行数についての合計を追加
test
CHANGED
@@ -37,3 +37,49 @@
|
|
37
37
|
>>>
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
タイトルが「上から○段目」なのですね。
|
44
|
+
|
45
|
+
足し算なら以下です。
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```python
|
50
|
+
|
51
|
+
>>> print(df)
|
52
|
+
|
53
|
+
C1 C2 C3
|
54
|
+
|
55
|
+
0 24 24 31
|
56
|
+
|
57
|
+
1 18 38 24
|
58
|
+
|
59
|
+
2 19 11 15
|
60
|
+
|
61
|
+
3 35 18 21
|
62
|
+
|
63
|
+
>>>
|
64
|
+
|
65
|
+
>>> def sum_cn(df, column, n):
|
66
|
+
|
67
|
+
... return sum(df[column].values[:n])
|
68
|
+
|
69
|
+
...
|
70
|
+
|
71
|
+
>>> print(sum_cn(df, 'C2', 2))
|
72
|
+
|
73
|
+
62
|
74
|
+
|
75
|
+
>>> print(sum_cn(df, 'C2', 3))
|
76
|
+
|
77
|
+
73
|
78
|
+
|
79
|
+
>>> print(sum_cn(df, 'C2', 4))
|
80
|
+
|
81
|
+
91
|
82
|
+
|
83
|
+
>>>
|
84
|
+
|
85
|
+
```
|