回答編集履歴
1
追記
test
CHANGED
@@ -55,3 +55,63 @@
|
|
55
55
|
"""
|
56
56
|
|
57
57
|
```
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
表示形式を指定
|
62
|
+
|
63
|
+
--
|
64
|
+
|
65
|
+
すこし面倒ですが、以下のようなコードにより、数値のまま表示形式を変えることもできます。
|
66
|
+
|
67
|
+
参考:[How to display pandas DataFrame of floats using a format string for columns?](https://stackoverflow.com/questions/20937538/how-to-display-pandas-dataframe-of-floats-using-a-format-string-for-columns)
|
68
|
+
|
69
|
+
```Python
|
70
|
+
|
71
|
+
import pandas as pd
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
# テストデータ
|
76
|
+
|
77
|
+
df = pd.DataFrame({'date':['2019-09-06'], 'close':[2335.0], 'hist':[-24.684088]})
|
78
|
+
|
79
|
+
df['date'] = pd.to_datetime(df['date'])
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
formatters = {} # 列ごとの書式
|
84
|
+
|
85
|
+
for c in df.select_dtypes(include=float).columns:
|
86
|
+
|
87
|
+
if c == 'hist':
|
88
|
+
|
89
|
+
formatters[c] = '{:.2f}'.format
|
90
|
+
|
91
|
+
else:
|
92
|
+
|
93
|
+
formatters[c] = '{:,.0f}'.format
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
print(df.to_string(formatters=formatters))
|
98
|
+
|
99
|
+
# date close hist
|
100
|
+
|
101
|
+
#0 2019-09-06 2,335 -24.68
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
print(df.dtypes)
|
106
|
+
|
107
|
+
"""
|
108
|
+
|
109
|
+
date datetime64[ns]
|
110
|
+
|
111
|
+
close float64
|
112
|
+
|
113
|
+
hist float64
|
114
|
+
|
115
|
+
"""
|
116
|
+
|
117
|
+
```
|