回答編集履歴
3
test
CHANGED
@@ -2,11 +2,10 @@
|
|
2
2
|
```python
|
3
3
|
import csv
|
4
4
|
|
5
|
-
cols = 'ABCDE'
|
6
5
|
with open('sample.txt') as f:
|
7
|
-
for r in csv.reader(f):
|
6
|
+
for r in csv.reader(f):
|
8
|
-
msg = ','.join(map(''.join, zip(
|
7
|
+
msg = ','.join(map(''.join, zip('ABCDE', r)))
|
9
|
-
print(msg)
|
8
|
+
print(msg)
|
10
9
|
|
11
10
|
# A10,B20,C30,D40,E50
|
12
11
|
# A40,B40,C34,D40,E50
|
2
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
```python
|
3
3
|
import csv
|
4
4
|
|
5
|
-
cols =
|
5
|
+
cols = 'ABCDE'
|
6
6
|
with open('sample.txt') as f:
|
7
7
|
for r in csv.reader(f):
|
8
8
|
msg = ','.join(map(''.join, zip(cols, r)))
|
1
test
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
>
|
1
|
+
> データの個数が異なるとき
|
2
|
+
```python
|
3
|
+
import csv
|
2
4
|
|
3
|
-
|
5
|
+
cols = [*'ABCDE']
|
6
|
+
with open('sample.txt') as f:
|
4
|
-
|
7
|
+
for r in csv.reader(f):
|
8
|
+
msg = ','.join(map(''.join, zip(cols, r)))
|
9
|
+
print(msg)
|
5
10
|
|
6
|
-
df = pd.read_csv('sample.txt', header=None, na_filter=False, dtype=str)
|
7
|
-
dfx = df.set_axis([*'ABCDE'], axis=1).apply(lambda x: x.name + x)
|
8
|
-
|
11
|
+
# A10,B20,C30,D40,E50
|
12
|
+
# A40,B40,C34,D40,E50
|
13
|
+
# A30,B49,C,D49,E58
|
14
|
+
# A10,B,C,D39,E40
|
15
|
+
# A10,B20,C30
|
9
16
|
```
|
10
|
-
|
11
|
-
**result.csv**
|
12
|
-
```csv
|
13
|
-
A10,B20,C30,D40,E50
|
14
|
-
A40,B40,C34,D40,E50
|
15
|
-
A30,B49,C,D49,E58
|
16
|
-
A10,B,C,D39,E40
|
17
|
-
```
|