回答編集履歴
1
パフォーマンス意識
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
df = pd.DataFrame({'A':range(10), 'B':range(10), 'C':range(10)})
|
10
10
|
|
11
|
-
np.random.shuffle(df.loc[:, 'A'])
|
11
|
+
np.random.shuffle(df.loc[:, 'A'].to_numpy())
|
12
12
|
|
13
13
|
|
14
14
|
|
@@ -37,3 +37,19 @@
|
|
37
37
|
# 9 9 9 9
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```Python
|
44
|
+
|
45
|
+
>>> %timeit df.iloc[:,0] = df.iloc[:,0].sample(frac=1).reset_index(drop=True)
|
46
|
+
|
47
|
+
412 µs ± 1.72 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
>>> %timeit np.random.shuffle(df.loc[:, 'A'].to_numpy())
|
52
|
+
|
53
|
+
40.3 µs ± 117 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
|
54
|
+
|
55
|
+
```
|