回答編集履歴
2
補足追加
test
CHANGED
@@ -95,3 +95,23 @@
|
|
95
95
|
#4 2020-03-05T00:00:00+09:00 5
|
96
96
|
|
97
97
|
```
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
---
|
102
|
+
|
103
|
+
**【更に追記】**
|
104
|
+
|
105
|
+
タイムゾーンの設定はこちらの方法でもいけた(1行の短縮)
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
```Python
|
110
|
+
|
111
|
+
df = pd.read_csv(io.StringIO(data), parse_dates=['date'])
|
112
|
+
|
113
|
+
# tzを設定してdate列をISO8601拡張表記の文字列に変換
|
114
|
+
|
115
|
+
df['date'] = df['date'].apply(lambda d: pd.Timestamp(d, tz='Asia/Tokyo').isoformat())
|
116
|
+
|
117
|
+
```
|
1
回答が間違っていたので修正
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
```
|
1
|
+
```Python
|
2
2
|
|
3
3
|
import pandas as pd
|
4
4
|
|
@@ -51,3 +51,47 @@
|
|
51
51
|
#4 2020-03-05T00:00:00+0900 5
|
52
52
|
|
53
53
|
```
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
---
|
58
|
+
|
59
|
+
**【追記】**
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
あっゴメン。`Timestamp.isoformat()` を使いたいのですね。
|
64
|
+
|
65
|
+
であれば、
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
```Python
|
70
|
+
|
71
|
+
df = pd.read_csv(io.StringIO(data), parse_dates=['date'])
|
72
|
+
|
73
|
+
# date列にタイムゾーンを設定
|
74
|
+
|
75
|
+
df['date'] = df['date'].dt.tz_localize('Asia/Tokyo')
|
76
|
+
|
77
|
+
# date列をISO8601拡張表記の文字列に変換
|
78
|
+
|
79
|
+
df['date'] = df['date'].apply(lambda d: pd.Timestamp(d).isoformat())
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
print(df)
|
84
|
+
|
85
|
+
# date value
|
86
|
+
|
87
|
+
#0 2020-03-01T00:00:00+09:00 1
|
88
|
+
|
89
|
+
#1 2020-03-02T00:00:00+09:00 2
|
90
|
+
|
91
|
+
#2 2020-03-03T00:00:00+09:00 3
|
92
|
+
|
93
|
+
#3 2020-03-04T00:00:00+09:00 4
|
94
|
+
|
95
|
+
#4 2020-03-05T00:00:00+09:00 5
|
96
|
+
|
97
|
+
```
|