回答編集履歴

8

修正

2019/06/01 08:48

投稿

YasuhiroNiji
YasuhiroNiji

スコア584

test CHANGED
@@ -28,9 +28,9 @@
28
28
 
29
29
  df = a.set_index([np.ones(len(a), dtype='int')])\
30
30
 
31
- .join(b.set_index([np.ones(len(b), dtype='int')]))\
31
+ .join(b.set_index([np.ones(len(b), dtype='int')]), rsuffix='_b')\
32
32
 
33
- .join(c.set_index([np.ones(len(b), dtype='int')]))\
33
+ .join(c.set_index([np.ones(len(b), dtype='int')]), lsuffix='_a', rsuffix='_c')\
34
34
 
35
35
  .reset_index(drop=True)
36
36
 

7

修正

2019/06/01 08:48

投稿

YasuhiroNiji
YasuhiroNiji

スコア584

test CHANGED
@@ -6,11 +6,11 @@
6
6
 
7
7
  with open('time.csv', 'w') as f:
8
8
 
9
- for at in a['atime']:
9
+ for at in a['time']:
10
10
 
11
- for bt in b['btime']:
11
+ for bt in b['time']:
12
12
 
13
- for ct in c['ctime']:
13
+ for ct in c['time']:
14
14
 
15
15
  f.write(f'{at},{bt},{ct}\n')
16
16
 
@@ -50,7 +50,7 @@
50
50
 
51
51
 
52
52
 
53
- df2 = pd.DataFrame(itertools.product(a['atime'], b['btime'], c['ctime']),
53
+ df2 = pd.DataFrame(itertools.product(a['time'], b['time'], c['time']),
54
54
 
55
55
  columns=['atime', 'btime', 'ctime'])
56
56
 

6

誤字修正

2019/06/01 08:33

投稿

YasuhiroNiji
YasuhiroNiji

スコア584

test CHANGED
@@ -50,10 +50,10 @@
50
50
 
51
51
 
52
52
 
53
- df2 = pd.DataFrame(itertools.product(a['atime'],b['btime'],c['ctime']),
53
+ df2 = pd.DataFrame(itertools.product(a['atime'], b['btime'], c['ctime']),
54
54
 
55
- columns=['atime','btime','ctime'])
55
+ columns=['atime', 'btime', 'ctime'])
56
56
 
57
- df.to_csv('time.csv')
57
+ df2.to_csv('time.csv')
58
58
 
59
59
  ```

5

修正

2019/06/01 08:26

投稿

YasuhiroNiji
YasuhiroNiji

スコア584

test CHANGED
@@ -37,3 +37,23 @@
37
37
  df.to_csv('time.csv')
38
38
 
39
39
  ```
40
+
41
+
42
+
43
+ itertoolsを使うのであれば次のように直接DataFrameに変換した方がずっと速いです。でも、joinを使う方が速いです。
44
+
45
+
46
+
47
+ ```python
48
+
49
+ import itertools
50
+
51
+
52
+
53
+ df2 = pd.DataFrame(itertools.product(a['atime'],b['btime'],c['ctime']),
54
+
55
+ columns=['atime','btime','ctime'])
56
+
57
+ df.to_csv('time.csv')
58
+
59
+ ```

4

修正

2019/06/01 08:25

投稿

YasuhiroNiji
YasuhiroNiji

スコア584

test CHANGED
@@ -26,13 +26,13 @@
26
26
 
27
27
 
28
28
 
29
- a.set_index([np.ones(len(a), dtype='int')],inplace=True)
29
+ df = a.set_index([np.ones(len(a), dtype='int')])\
30
30
 
31
- b.set_index([np.ones(len(b), dtype='int')],inplace=True)
31
+ .join(b.set_index([np.ones(len(b), dtype='int')]))\
32
32
 
33
- c.set_index([np.ones(len(c), dtype='int')],inplace=True)
33
+ .join(c.set_index([np.ones(len(b), dtype='int')]))\
34
34
 
35
- df = a.join(b).join(c)
35
+ .reset_index(drop=True)
36
36
 
37
37
  df.to_csv('time.csv')
38
38
 

3

修正

2019/06/01 07:45

投稿

YasuhiroNiji
YasuhiroNiji

スコア584

test CHANGED
@@ -26,13 +26,11 @@
26
26
 
27
27
 
28
28
 
29
- s = np.ones(len(a), dtype='int')
29
+ a.set_index([np.ones(len(a), dtype='int')],inplace=True)
30
30
 
31
- a.set_index([s],inplace=True)
31
+ b.set_index([np.ones(len(b), dtype='int')],inplace=True)
32
32
 
33
- b.set_index([s],inplace=True)
34
-
35
- c.set_index([s],inplace=True)
33
+ c.set_index([np.ones(len(c), dtype='int')],inplace=True)
36
34
 
37
35
  df = a.join(b).join(c)
38
36
 

2

修正

2019/06/01 06:01

投稿

YasuhiroNiji
YasuhiroNiji

スコア584

test CHANGED
@@ -22,6 +22,10 @@
22
22
 
23
23
  ```python
24
24
 
25
+ import numpy as np
26
+
27
+
28
+
25
29
  s = np.ones(len(a), dtype='int')
26
30
 
27
31
  a.set_index([s],inplace=True)

1

回答の追加

2019/06/01 05:57

投稿

YasuhiroNiji
YasuhiroNiji

スコア584

test CHANGED
@@ -15,3 +15,23 @@
15
15
  f.write(f'{at},{bt},{ct}\n')
16
16
 
17
17
  ```
18
+
19
+
20
+
21
+ Pandasだけで完結したいのであれば、join又はmergeを使う方法があります。
22
+
23
+ ```python
24
+
25
+ s = np.ones(len(a), dtype='int')
26
+
27
+ a.set_index([s],inplace=True)
28
+
29
+ b.set_index([s],inplace=True)
30
+
31
+ c.set_index([s],inplace=True)
32
+
33
+ df = a.join(b).join(c)
34
+
35
+ df.to_csv('time.csv')
36
+
37
+ ```