質問編集履歴
7
コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,27 +1,3 @@
|
|
1
|
-
【実行したいこと】
|
2
|
-
|
3
|
-
1.エクセルをImport
|
4
|
-
|
5
|
-
2.指定の言葉が入ってる行のみ抽出
|
6
|
-
|
7
|
-
3.GroupByでまとめ
|
8
|
-
|
9
|
-
4.指定の文字を含む行の数字を確認
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
【試したこと調査したこと】
|
14
|
-
|
15
|
-
1.行を抽出する方法
|
16
|
-
|
17
|
-
https://note.nkmk.me/python-pandas-str-contains-match/
|
18
|
-
|
19
|
-
https://deepage.net/features/pandas-cond-extraction.html
|
20
|
-
|
21
|
-
指定でできるかなと
|
22
|
-
|
23
|
-
|
24
|
-
|
25
1
|
```
|
26
2
|
|
27
3
|
import pandas as pd
|
@@ -58,34 +34,220 @@
|
|
58
34
|
|
59
35
|
```
|
60
36
|
|
61
|
-
|
62
|
-
|
63
|
-
CSV
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
10
|
84
|
-
|
85
|
-
20
|
86
|
-
|
87
|
-
30
|
88
|
-
|
89
|
-
30
|
90
|
-
|
91
|
-
n
|
37
|
+
|
38
|
+
|
39
|
+
```CSV
|
40
|
+
|
41
|
+
時間,合計売上,一個値段,お店,商品,地域,,,,,,,,,,,,,,,,,,
|
42
|
+
|
43
|
+
"Jul 1, 2019 - Jan 13, 2020",133326.70,1452.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
44
|
+
|
45
|
+
"Jul 1, 2019 - Jan 13, 2020",9395.19,102.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
46
|
+
|
47
|
+
"Jul 1, 2019 - Jan 13, 2020",127079.27,1375.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
48
|
+
|
49
|
+
"Jul 1, 2019 - Jan 13, 2020",132558.81,1465.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
50
|
+
|
51
|
+
"Jul 1, 2019 - Jan 13, 2020",170284.76,1904.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
52
|
+
|
53
|
+
"Jul 1, 2019 - Jan 13, 2020",54659.79,785.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
54
|
+
|
55
|
+
"Jul 1, 2019 - Jan 13, 2020",190579.11,2101.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
56
|
+
|
57
|
+
"Jul 1, 2019 - Jan 13, 2020",280390.71,3077.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
58
|
+
|
59
|
+
"Jul 1, 2019 - Jan 13, 2020",1237384.22,15799.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
60
|
+
|
61
|
+
"Jul 1, 2019 - Jan 13, 2020",154110.71,2937.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
62
|
+
|
63
|
+
"Jul 1, 2019 - Jan 13, 2020",790624.08,9335.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
64
|
+
|
65
|
+
"Jul 1, 2019 - Jan 13, 2020",282542.22,4369.00,八百屋,りんご,千葉,,,,,,,,,,,,,,,,,,
|
66
|
+
|
67
|
+
"Jul 1, 2019 - Jan 13, 2020",340191.81,4404.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
68
|
+
|
69
|
+
"Jul 1, 2019 - Jan 13, 2020",582867.70,7924.00,八百屋,りんご,千葉,,,,,,,,,,,,,,,,,,
|
70
|
+
|
71
|
+
"Jul 1, 2019 - Jan 13, 2020",468990.85,6365.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
72
|
+
|
73
|
+
"Jul 1, 2019 - Jan 13, 2020",64832.70,712.00,八百屋,りんご,千葉,,,,,,,,,,,,,,,,,,
|
74
|
+
|
75
|
+
"Jul 1, 2019 - Jan 13, 2020",168614.78,1850.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
76
|
+
|
77
|
+
"Jul 1, 2019 - Jan 13, 2020",49834.91,550.00,八百屋,りんご,東京,,,,,,,,,,,,,,,,,,
|
78
|
+
|
79
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
80
|
+
|
81
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
82
|
+
|
83
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
84
|
+
|
85
|
+
"Jul 1, 2019 - Jan 13, 2020",16019.16,495.00,八百屋,レモン,東京,,,,,,,,,,,,,,,,,,
|
86
|
+
|
87
|
+
"Jul 1, 2019 - Jan 13, 2020",16100.74,435.00,八百屋,レモン,東京,,,,,,,,,,,,,,,,,,
|
88
|
+
|
89
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
90
|
+
|
91
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
92
|
+
|
93
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
94
|
+
|
95
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
96
|
+
|
97
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
98
|
+
|
99
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
100
|
+
|
101
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
102
|
+
|
103
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
104
|
+
|
105
|
+
"Jul 1, 2019 - Jan 13, 2020",2752.97,64.00,八百屋,レモン,東京,,,,,,,,,,,,,,,,,,
|
106
|
+
|
107
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
108
|
+
|
109
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
110
|
+
|
111
|
+
"Jul 1, 2019 - Jan 13, 2020",0.00,0,-,レモン,東京,,,,,,,,,,,,,,,,,,
|
112
|
+
|
113
|
+
"Jul 1, 2019 - Jan 13, 2020",15671.61,427.00,八百屋,レモン,東京,,,,,,,,,,,,,,,,,,
|
114
|
+
|
115
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,レモン,神奈川,,,,,,,,,,,,,,,,,,
|
116
|
+
|
117
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,レモン,神奈川,,,,,,,,,,,,,,,,,,
|
118
|
+
|
119
|
+
"Jul 1, 2019 - Mar 31, 2020",3591.89,29.00,八百屋,レモン,神奈川,,,,,,,,,,,,,,,,,,
|
120
|
+
|
121
|
+
"Jul 1, 2019 - Mar 31, 2020",190.00,1.00,八百屋,レモン,神奈川,,,,,,,,,,,,,,,,,,
|
122
|
+
|
123
|
+
"Jul 1, 2019 - Mar 31, 2020",456.60,2.00,八百屋,レモン,神奈川,,,,,,,,,,,,,,,,,,
|
124
|
+
|
125
|
+
"Jul 1, 2019 - Mar 31, 2020",320.00,3.00,八百屋,レモン,神奈川,,,,,,,,,,,,,,,,,,
|
126
|
+
|
127
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,レモン,神奈川,,,,,,,,,,,,,,,,,,
|
128
|
+
|
129
|
+
"Jul 1, 2019 - Mar 31, 2020",1457.67,8.00,八百屋,レモン,神奈川,,,,,,,,,,,,,,,,,,
|
130
|
+
|
131
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,1.00,八百屋,レモン,神奈川,,,,,,,,,,,,,,,,,,
|
132
|
+
|
133
|
+
"Jul 1, 2019 - Mar 31, 2020",137.56,1.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
134
|
+
|
135
|
+
"Jul 1, 2019 - Mar 31, 2020",2002.30,12.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
136
|
+
|
137
|
+
"Jul 1, 2019 - Mar 31, 2020",90.69,2.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
138
|
+
|
139
|
+
"Jul 1, 2019 - Mar 31, 2020",500.00,2.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
140
|
+
|
141
|
+
"Jul 1, 2019 - Mar 31, 2020",390.00,3.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
142
|
+
|
143
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,1.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
144
|
+
|
145
|
+
"Jul 1, 2019 - Mar 31, 2020",250.00,2.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
146
|
+
|
147
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
148
|
+
|
149
|
+
"Jul 1, 2019 - Mar 31, 2020",2521.32,15.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
150
|
+
|
151
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
152
|
+
|
153
|
+
"Jul 1, 2019 - Mar 31, 2020",800.00,6.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
154
|
+
|
155
|
+
"Jul 1, 2019 - Mar 31, 2020",297.69,3.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
156
|
+
|
157
|
+
"Jul 1, 2019 - Mar 31, 2020",72.55,2.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
158
|
+
|
159
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
160
|
+
|
161
|
+
"Jul 1, 2019 - Mar 31, 2020",1208.90,7.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
162
|
+
|
163
|
+
"Jul 1, 2019 - Mar 31, 2020",200.00,1.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
164
|
+
|
165
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
166
|
+
|
167
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
168
|
+
|
169
|
+
"Jul 1, 2019 - Mar 31, 2020",1075.00,7.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
170
|
+
|
171
|
+
"Jul 1, 2019 - Mar 31, 2020",187.56,1.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
172
|
+
|
173
|
+
"Jul 1, 2019 - Mar 31, 2020",2542.74,13.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
174
|
+
|
175
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
176
|
+
|
177
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,2.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
178
|
+
|
179
|
+
"Jul 1, 2019 - Mar 31, 2020",370.50,4.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
180
|
+
|
181
|
+
"Jul 1, 2019 - Mar 31, 2020",640.00,2.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
182
|
+
|
183
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
184
|
+
|
185
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
186
|
+
|
187
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
188
|
+
|
189
|
+
"Jul 1, 2019 - Mar 31, 2020",268.22,3.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
190
|
+
|
191
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,2.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
192
|
+
|
193
|
+
"Jul 1, 2019 - Mar 31, 2020",650.00,5.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
194
|
+
|
195
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
196
|
+
|
197
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
198
|
+
|
199
|
+
"Jul 1, 2019 - Mar 31, 2020",448.64,3.00,八百屋,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
200
|
+
|
201
|
+
"Jul 1, 2019 - Mar 31, 2020",0.00,0,-,みかん,神奈川,,,,,,,,,,,,,,,,,,
|
202
|
+
|
203
|
+
"Jul 1, 2019 - May 31, 2020",0.00,0.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
204
|
+
|
205
|
+
"Jul 1, 2019 - May 31, 2020",5905.37,260.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
206
|
+
|
207
|
+
"Jul 1, 2019 - May 31, 2020",7360.01,350.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
208
|
+
|
209
|
+
"Jul 1, 2019 - May 31, 2020",31.16,2.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
210
|
+
|
211
|
+
"Jul 1, 2019 - May 31, 2020",35.00,2.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
212
|
+
|
213
|
+
"Jul 1, 2019 - May 31, 2020",1708.10,81.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
214
|
+
|
215
|
+
"Jul 1, 2019 - May 31, 2020",1379.71,66.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
216
|
+
|
217
|
+
"Jul 1, 2019 - May 31, 2020",334.06,17.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
218
|
+
|
219
|
+
"Jul 1, 2019 - May 31, 2020",18.99,2.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
220
|
+
|
221
|
+
"Jul 1, 2019 - May 31, 2020",18.05,1.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
222
|
+
|
223
|
+
"Jul 1, 2019 - May 31, 2020",171.22,6.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
224
|
+
|
225
|
+
"Jul 1, 2019 - May 31, 2020",6.07,1.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
226
|
+
|
227
|
+
"Jul 1, 2019 - May 31, 2020",1826.98,61.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
228
|
+
|
229
|
+
"Jul 1, 2019 - May 31, 2020",105.05,4.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
230
|
+
|
231
|
+
"Jul 1, 2019 - May 31, 2020",104.76,4.00,スーパー,もも,千葉,,,,,,,,,,,,,,,,,,
|
232
|
+
|
233
|
+
"Jul 1, 2019 - May 31, 2020",1592.57,29.00,スーパー,ぶどう,千葉,,,,,,,,,,,,,,,,,,
|
234
|
+
|
235
|
+
"Jul 1, 2019 - May 31, 2020",3019.90,42.00,スーパー,ぶどう,千葉,,,,,,,,,,,,,,,,,,
|
236
|
+
|
237
|
+
"Jul 1, 2019 - May 31, 2020",57150.99,1052.00,スーパー,ぶどう,千葉,,,,,,,,,,,,,,,,,,
|
238
|
+
|
239
|
+
"Jul 1, 2019 - May 31, 2020",164671.87,3485.00,スーパー,ぶどう,千葉,,,,,,,,,,,,,,,,,,
|
240
|
+
|
241
|
+
"Jul 1, 2019 - May 31, 2020",5031.62,93.00,スーパー,ぶどう,千葉,,,,,,,,,,,,,,,,,,
|
242
|
+
|
243
|
+
"Jul 1, 2019 - May 31, 2020",33436.22,622.00,スーパー,ぶどう,千葉,,,,,,,,,,,,,,,,,,
|
244
|
+
|
245
|
+
"Jul 1, 2019 - May 31, 2020",79.28,4.00,スーパー,ぶどう,千葉,,,,,,,,,,,,,,,,,,
|
246
|
+
|
247
|
+
"Jul 1, 2019 - May 31, 2020",1043.03,25.00,スーパー,ぶどう,千葉,,,,,,,,,,,,,,,,,,
|
248
|
+
|
249
|
+
"Jul 1, 2019 - May 31, 2020",6249.51,156.00,スーパー,ぶどう,千葉,,,,,,,,,,,,,,,,,,
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
```
|
6
コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
#八百屋だけだす#合計値をだす
|
38
38
|
|
39
|
-
grp=df[df['お店']=='八百屋'].groupby(['お店','商品'
|
39
|
+
grp=df[df['お店']=='八百屋'].groupby(['地域','お店','商品'],as_index='地域').sum().round(0)
|
40
40
|
|
41
41
|
#個数を入れる
|
42
42
|
|
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
-
#
|
51
|
+
#商品ごとの合計売上の平均、最大、商品ごとのの出現回数などを出したい。
|
52
52
|
|
53
53
|
#失敗のコード
|
54
54
|
|
@@ -62,9 +62,11 @@
|
|
62
62
|
|
63
63
|
CSVをそのままあげる方法がわからず、結果と表の例を記入させていただきます。
|
64
64
|
|
65
|
+
りんごの合計売上の平均はりんごの合計売上の最大は?りんごの頻出回数は?
|
65
66
|
|
67
|
+
などを商品ごとに出したい。
|
66
68
|
|
67
|
-
![イメージ説明](0
|
69
|
+
![イメージ説明](80d0a9a7f726123cbb71e59284798988.png)
|
68
70
|
|
69
71
|
|
70
72
|
|
5
コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -48,7 +48,7 @@
|
|
48
48
|
|
49
49
|
|
50
50
|
|
51
|
-
#神奈川
|
51
|
+
#神奈川合計売上の平均、最大、神奈川の出現回数などを出したい。
|
52
52
|
|
53
53
|
#失敗のコード
|
54
54
|
|
4
コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,76 +20,70 @@
|
|
20
20
|
|
21
21
|
指定でできるかなと
|
22
22
|
|
23
|
-
grp[['合計金額','価格']].round(0).grp[['レモン']]
|
24
23
|
|
25
|
-
grp[['合計金額','価格'=='レモン']]などを試してみましがわからないのでご教授お願いします
|
26
|
-
|
27
|
-
実際のコード
|
28
24
|
|
29
25
|
```
|
30
26
|
|
31
|
-
|
27
|
+
import pandas as pd
|
32
|
-
|
33
|
-
df1[df1['お店の名前']=='八百屋'].head()
|
34
|
-
|
35
|
-
grp=df1[df1['お店の名前']=='八百屋'].groupby(['地域', 'お店の名前','商品名'] ,as_index='地域').sum().round(0)
|
36
28
|
|
37
29
|
|
38
30
|
|
39
|
-
|
31
|
+
pd.set_option('display.max_rows', 150)
|
40
32
|
|
33
|
+
df=pd.read_csv('testcopy.csv')
|
34
|
+
|
35
|
+
df
|
36
|
+
|
37
|
+
#八百屋だけだす#合計値をだす
|
38
|
+
|
39
|
+
grp=df[df['お店']=='八百屋'].groupby(['お店','商品','地域'],as_index='地域').sum().round(0)
|
40
|
+
|
41
|
+
#個数を入れる
|
42
|
+
|
43
|
+
grp['個数']=grp['合計売上']/grp['一個値段'].round(0)
|
44
|
+
|
45
|
+
#必要な情報だけだす
|
46
|
+
|
41
|
-
grp[['合計
|
47
|
+
grp[['合計売上','一個値段','個数']]
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
#神奈川のみかんの合計売上の平均、最大、神奈川の出現回数などを出したい。
|
52
|
+
|
53
|
+
#失敗のコード
|
54
|
+
|
55
|
+
grp[['合計売上','一個値段','個数'=='神奈川]].mean()
|
56
|
+
|
57
|
+
grp['神奈川'].mean()
|
42
58
|
|
43
59
|
```
|
44
60
|
|
45
|
-
|
46
|
-
|
47
61
|
【結果】
|
48
62
|
|
49
|
-
|列1|列2|列3|列4|列5|
|
50
|
-
|
51
|
-
|:--|:--:|--:|--:|--:|
|
52
|
-
|
53
|
-
|地域|お店の名前|商品名|合計金額|価格
|
54
|
-
|
55
|
-
|
63
|
+
CSVをそのままあげる方法がわからず、結果と表の例を記入させていただきます。
|
56
|
-
|
57
|
-
東京|B|E|1000|100000|10000000
|
58
|
-
|
59
|
-
千葉|C|F|1000|100000|10000000
|
60
64
|
|
61
65
|
|
62
66
|
|
63
|
-
実際には三つ指定してGroupByしてるので、A,B、C列では階層になっております。
|
64
|
-
|
65
|
-
今回はCの階層を調べたい。
|
66
|
-
|
67
|
-
![イメージ説明](
|
67
|
+
![イメージ説明](0a4704b66dccacad409f5612041a17b4.png)
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
-
【欲しい結果】
|
72
|
-
|
73
|
-
C列が例えば
|
74
|
-
|
75
|
-
商品名
|
76
|
-
|
77
|
-
神奈川 お店A
|
78
|
-
|
79
|
-
りんご 200
|
80
|
-
|
81
|
-
レモン 100
|
82
|
-
|
83
|
-
東京 お店B
|
84
|
-
|
85
|
-
りんご 200
|
86
|
-
|
87
|
-
レモン 100
|
88
|
-
|
89
|
-
みかん 200
|
90
71
|
|
91
72
|
|
92
73
|
|
93
|
-
ってあった場合に
|
94
74
|
|
75
|
+
|列1|列2|列3|列1|列2|
|
76
|
+
|
77
|
+
|:--|:--:|--:|
|
78
|
+
|
79
|
+
合計売上|一個値段|お店|商品|地域
|
80
|
+
|
81
|
+
10|2|お店|りごご|神奈川
|
82
|
+
|
95
|
-
|
83
|
+
20|2|お店|みかん|千葉
|
84
|
+
|
85
|
+
30|3|お店|レモン|東京
|
86
|
+
|
87
|
+
30|3|お店|レモン|東京
|
88
|
+
|
89
|
+
n|n|n|n|n
|
3
試したこと
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,9 +10,19 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
+
【試したこと調査したこと】
|
13
14
|
|
15
|
+
1.行を抽出する方法
|
14
16
|
|
17
|
+
https://note.nkmk.me/python-pandas-str-contains-match/
|
15
18
|
|
19
|
+
https://deepage.net/features/pandas-cond-extraction.html
|
20
|
+
|
21
|
+
指定でできるかなと
|
22
|
+
|
23
|
+
grp[['合計金額','価格']].round(0).grp[['レモン']]
|
24
|
+
|
25
|
+
grp[['合計金額','価格'=='レモン']]などを試してみましがわからないのでご教授お願いします
|
16
26
|
|
17
27
|
実際のコード
|
18
28
|
|
2
コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
-
grp['価格']=grp
|
29
|
+
grp['価格']=grp['合計金額']/grp['個数'].round(0)
|
30
30
|
|
31
31
|
grp[['合計金額','価格']].round(0)
|
32
32
|
|
1
コード
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
df1[df1['お店の名前']=='八百屋'].head()
|
24
24
|
|
25
|
-
grp=df1[df1['お店の名前']=='八百屋'].groupby(['地域', 'お店の名前','商品名'] ,as_index='
|
25
|
+
grp=df1[df1['お店の名前']=='八百屋'].groupby(['地域', 'お店の名前','商品名'] ,as_index='地域').sum().round(0)
|
26
26
|
|
27
27
|
|
28
28
|
|