回答編集履歴
1
追記
answer
CHANGED
@@ -1,2 +1,19 @@
|
|
1
1
|
`df.to_excel('~.xls', index=None)`のように`header`を指定しないとデータフレームの列名が自動で出力されるはずです。
|
2
|
-
もし出力されない場合は`df.to_excel('~.xls', header=df.columns, index=None)`と指定してみてください。
|
2
|
+
もし出力されない場合は`df.to_excel('~.xls', header=df.columns, index=None)`と指定してみてください。
|
3
|
+
|
4
|
+
なお、データフレーム自体の列名は以下のようにして一括指定できます。
|
5
|
+
|
6
|
+
```Python
|
7
|
+
import pandas as pd
|
8
|
+
pd.set_option('display.unicode.east_asian_width', True)
|
9
|
+
|
10
|
+
df = pd.DataFrame([[1,2,3,4,5]])
|
11
|
+
print(df)
|
12
|
+
# 0 1 2 3 4
|
13
|
+
#0 1 2 3 4 5
|
14
|
+
|
15
|
+
df.columns = ['{}列目'.format(i+1) for i in range(len(df.columns))]
|
16
|
+
print(df)
|
17
|
+
# 1列目 2列目 3列目 4列目 5列目
|
18
|
+
#0 1 2 3 4 5
|
19
|
+
```
|