回答編集履歴

4

修正

2022/04/14 15:01

投稿

meg_
meg_

スコア10580

test CHANGED
@@ -36,8 +36,8 @@
36
36
  df.loc[df.Type=="FF", "Score1"] = np.random.sample(len(df[df.Type=="FF"]))*10+150
37
37
  df.loc[df.Type=="SL", "Score1"] = np.random.sample(len(df[df.Type=="SL"]))*10+140
38
38
  df.loc[df.Type=="CU", "Score1"] = np.random.sample(len(df[df.Type=="CU"]))*10+130
39
- Type Score1
39
+ # Type Score1
40
- 0 SL 146.079588
40
+ #0 SL 146.079588
41
41
  #1 SL 140.209451
42
42
  #2 CU 137.696889
43
43
  #3 SL 146.422702

3

コードを修正

2022/04/14 14:58

投稿

meg_
meg_

スコア10580

test CHANGED
@@ -27,24 +27,25 @@
27
27
 
28
28
  ---
29
29
  追加の質問への回答です。
30
- 下記のように書くことができます。
30
+ 下記のように書くことができます。※コードを一部修正しました。
31
31
  ```python
32
+ N = 1000
32
33
  type = ["FF","SL","CU"]
33
34
  type = np.random.choice(type,size=N)
34
35
  df = pd.DataFrame({"Type":type})
35
- df.loc[df.Type=="FF", "Score1"] = np.random.rand()*10+150
36
+ df.loc[df.Type=="FF", "Score1"] = np.random.sample(len(df[df.Type=="FF"]))*10+150
36
- df.loc[df.Type=="SL", "Score1"] = np.random.rand()*10+140
37
+ df.loc[df.Type=="SL", "Score1"] = np.random.sample(len(df[df.Type=="SL"]))*10+140
37
- df.loc[df.Type=="CU", "Score1"] = np.random.rand()*10+130
38
+ df.loc[df.Type=="CU", "Score1"] = np.random.sample(len(df[df.Type=="CU"]))*10+130
38
- # Type Score1
39
+ Type Score1
40
+ 0 SL 146.079588
39
- #0 SL 149.74
41
+ #1 SL 140.209451
40
- #1 CU 138.11
42
+ #2 CU 137.696889
43
+ #3 SL 146.422702
41
- #2 FF 157.42
44
+ #4 FF 151.401674
42
- #3 FF 157.42
43
- #4 CU 138.11
44
45
  #... ... ...
46
+ #995 SL 149.747729
47
+ #996 SL 148.082197
48
+ #997 SL 143.090960
45
- #995 FF 157.42
49
+ #998 FF 154.045560
46
- #996 CU 138.11
47
- #997 CU 138.11
48
- #998 CU 138.11
49
- #999 CU 138.11
50
+ #999 FF 152.727737
50
51
  ```

2

修正

2022/04/14 13:11

投稿

meg_
meg_

スコア10580

test CHANGED
@@ -29,21 +29,22 @@
29
29
  追加の質問への回答です。
30
30
  下記のように書くことができます。
31
31
  ```python
32
+ type = ["FF","SL","CU"]
32
33
  type = np.random.choice(type,size=N)
33
34
  df = pd.DataFrame({"Type":type})
34
35
  df.loc[df.Type=="FF", "Score1"] = np.random.rand()*10+150
35
36
  df.loc[df.Type=="SL", "Score1"] = np.random.rand()*10+140
36
37
  df.loc[df.Type=="CU", "Score1"] = np.random.rand()*10+130
37
38
  # Type Score1
38
- #0 FF 150.19
39
- #1 SL 142.07
39
+ #0 SL 149.74
40
+ #1 CU 138.11
40
- #2 FF 150.19
41
+ #2 FF 157.42
41
- #3 SL 142.07
42
+ #3 FF 157.42
42
- #4 SL 142.07
43
+ #4 CU 138.11
43
44
  #... ... ...
44
- #995 SL 142.07
45
+ #995 FF 157.42
45
- #996 SL 142.07
46
+ #996 CU 138.11
46
- #997 SL 142.07
47
+ #997 CU 138.11
47
- #998 SL 142.07
48
+ #998 CU 138.11
48
- #999 SL 142.07
49
+ #999 CU 138.11
49
50
  ```

1

追加の質問への回答を追記

2022/04/14 13:07

投稿

meg_
meg_

スコア10580

test CHANGED
@@ -24,3 +24,26 @@
24
24
  #998 SL 147.17 52.88 -9.30
25
25
  #999 FF 152.69 29.36 31.51
26
26
  ```
27
+
28
+ ---
29
+ 追加の質問への回答です。
30
+ 下記のように書くことができます。
31
+ ```python
32
+ type = np.random.choice(type,size=N)
33
+ df = pd.DataFrame({"Type":type})
34
+ df.loc[df.Type=="FF", "Score1"] = np.random.rand()*10+150
35
+ df.loc[df.Type=="SL", "Score1"] = np.random.rand()*10+140
36
+ df.loc[df.Type=="CU", "Score1"] = np.random.rand()*10+130
37
+ # Type Score1
38
+ #0 FF 150.19
39
+ #1 SL 142.07
40
+ #2 FF 150.19
41
+ #3 SL 142.07
42
+ #4 SL 142.07
43
+ #... ... ...
44
+ #995 SL 142.07
45
+ #996 SL 142.07
46
+ #997 SL 142.07
47
+ #998 SL 142.07
48
+ #999 SL 142.07
49
+ ```