回答編集履歴
1
修正
test
CHANGED
@@ -63,3 +63,71 @@
|
|
63
63
|
#7 17 18 4
|
64
64
|
|
65
65
|
```
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
---
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
**【ちょっと間違っていたので修正】**
|
74
|
+
|
75
|
+
timestampを残すにはこちらの方がよいかな
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
```Python
|
80
|
+
|
81
|
+
import pandas as pd
|
82
|
+
|
83
|
+
import io
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
data = """
|
88
|
+
|
89
|
+
timestamp,data1,data2,data3,data4,data5,data6,data7,data8
|
90
|
+
|
91
|
+
aaa,1,2,3,4,5,6,7,8
|
92
|
+
|
93
|
+
bbb,11,12,13,14,15,16,17,18
|
94
|
+
|
95
|
+
"""
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
df = pd.read_csv(io.StringIO(data))
|
100
|
+
|
101
|
+
print(df)
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
def f(data):
|
106
|
+
|
107
|
+
return pd.DataFrame(data.loc[:, 'data1':].values.reshape(4,2))
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
new_df = df.groupby('timestamp').apply(f).reset_index().rename(columns={'level_1':'CH'})
|
112
|
+
|
113
|
+
new_df.CH += 1
|
114
|
+
|
115
|
+
# timestamp CH 0 1
|
116
|
+
|
117
|
+
#0 aaa 1 1 2
|
118
|
+
|
119
|
+
#1 aaa 2 3 4
|
120
|
+
|
121
|
+
#2 aaa 3 5 6
|
122
|
+
|
123
|
+
#3 aaa 4 7 8
|
124
|
+
|
125
|
+
#4 bbb 1 11 12
|
126
|
+
|
127
|
+
#5 bbb 2 13 14
|
128
|
+
|
129
|
+
#6 bbb 3 15 16
|
130
|
+
|
131
|
+
#7 bbb 4 17 18
|
132
|
+
|
133
|
+
```
|