質問編集履歴
2
df_3の数値を修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
#実行後のイメージ
|
38
38
|
|
39
|
-
data_3={"category":["a","a","a","b","b","c","c","c","c"],"num":[10,8,5,6,
|
39
|
+
data_3={"category":["a","a","a","b","b","c","c","c","c"],"num":[10,8,5,6,5,13,9,5,2]}
|
40
40
|
|
41
41
|
df_3= pd.DataFrame(data_3)
|
42
42
|
|
1
実行後のイメージを追記いたしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
d
|
3
|
+
df_2の"num"の数値をdf_1にある"categoryの個数毎に上位の数値順に取得した列をdf_1に追加し、df_3を作りたいと考えていますが、方法がわかりません。
|
4
4
|
|
5
5
|
|
6
6
|
|
7
7
|
教えていただけないでしょうか
|
8
|
+
|
9
|
+
|
8
10
|
|
9
11
|
|
10
12
|
|
@@ -18,6 +20,8 @@
|
|
18
20
|
|
19
21
|
import numpy as np
|
20
22
|
|
23
|
+
#実行前のデータ
|
24
|
+
|
21
25
|
data_1 = {"category":["a","a","a","b","b","c","c","c","c"]}
|
22
26
|
|
23
27
|
df_1 = pd.DataFrame(data_1)
|
@@ -28,4 +32,18 @@
|
|
28
32
|
|
29
33
|
df_2 = pd.DataFrame(data_2)
|
30
34
|
|
35
|
+
|
36
|
+
|
37
|
+
#実行後のイメージ
|
38
|
+
|
39
|
+
data_3={"category":["a","a","a","b","b","c","c","c","c"],"num":[10,8,5,6,3,13,9,5,2]}
|
40
|
+
|
41
|
+
df_3= pd.DataFrame(data_3)
|
42
|
+
|
31
43
|
```
|
44
|
+
|
45
|
+
修正
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
df_1をdf_2の数値に基づいて、df_3にしたいと考えています。
|