回答編集履歴
1
コメントへの回答追加
test
CHANGED
@@ -29,3 +29,83 @@
|
|
29
29
|
writer.writerows(df.T.reset_index().T.values.tolist())
|
30
30
|
|
31
31
|
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
カラムだけに""を付けることはできるでしょうか?
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
たぶん、以下で出来ます。
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```python
|
44
|
+
|
45
|
+
import csv
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
for file in files:#すべてのファイルに以下を繰り返し実行
|
50
|
+
|
51
|
+
df=pd.read_csv(file)
|
52
|
+
|
53
|
+
df.insert(5, "","")#4列目に空の列を挿入
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
column=["日付","始値","高値","安値","終値","前日比","出来高","売残","買残"]
|
58
|
+
|
59
|
+
df.columns=column
|
60
|
+
|
61
|
+
fname=os.path.basename(file)#パスを除いた拡張子付きのファイル名のみを抽出
|
62
|
+
|
63
|
+
with open("/content/drive/MyDrive/処理済み株価/"+fname, "w", encoding='utf_8_sig') as f:
|
64
|
+
|
65
|
+
writer_q = csv.writer(f, quoting=csv.QUOTE_NONNUMERIC)
|
66
|
+
|
67
|
+
writer_q.writerow(column)
|
68
|
+
|
69
|
+
writer = csv.writer(f)
|
70
|
+
|
71
|
+
writer.writerows(df.values.tolist())
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
ダメな場合は、以下を試してみてください。
|
78
|
+
|
79
|
+
```python
|
80
|
+
|
81
|
+
import csv
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
for file in files:#すべてのファイルに以下を繰り返し実行
|
86
|
+
|
87
|
+
df=pd.read_csv(file)
|
88
|
+
|
89
|
+
df.insert(5, "","")#4列目に空の列を挿入
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
column=["日付","始値","高値","安値","終値","前日比","出来高","売残","買残"]
|
94
|
+
|
95
|
+
df.columns=column
|
96
|
+
|
97
|
+
fname=os.path.basename(file)#パスを除いた拡張子付きのファイル名のみを抽出
|
98
|
+
|
99
|
+
with open("/content/drive/MyDrive/処理済み株価/"+fname, "w", encoding='utf_8_sig') as f:
|
100
|
+
|
101
|
+
writer_q = csv.writer(f, quoting=csv.QUOTE_NONNUMERIC)
|
102
|
+
|
103
|
+
writer_q.writerow(column)
|
104
|
+
|
105
|
+
with open("/content/drive/MyDrive/処理済み株価/"+fname, "a", encoding='utf_8_sig') as f:
|
106
|
+
|
107
|
+
writer = csv.writer(f)
|
108
|
+
|
109
|
+
writer.writerows(df.values.tolist())
|
110
|
+
|
111
|
+
```
|