回答編集履歴
1
追記
test
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
|
2
2
|
[Index.map](https://pandas.pydata.org/docs/reference/api/pandas.Index.map.html#pandas.Index.map)で処理してやればよいです。
|
3
|
+
あるいは先頭行と指定日時の差分をとって、その差分(timedelta)をindexから引けばよいです。
|
3
4
|
```Python
|
4
5
|
from dateutil.relativedelta import relativedelta
|
5
6
|
import pandas as pd
|
@@ -9,8 +10,8 @@
|
|
9
10
|
2021/04/01 0:30,1
|
10
11
|
2021/04/01 1:00,2
|
11
12
|
2021/04/01 1:30,3"""
|
13
|
+
|
12
14
|
df = pd.read_csv(StringIO(s), parse_dates=['A'], index_col=['A'])
|
13
|
-
|
14
15
|
df.index = df.index.map(lambda x: x - relativedelta(years=1) + relativedelta(minutes=30))
|
15
16
|
print(df)
|
16
17
|
"""
|
@@ -20,4 +21,15 @@
|
|
20
21
|
2020-04-01 01:30:00 2
|
21
22
|
2020-04-01 02:00:00 3
|
22
23
|
"""
|
24
|
+
|
25
|
+
df = pd.read_csv(StringIO(s), parse_dates=['A'], index_col=['A'])
|
26
|
+
df.index = df.index - (df.index[0] - pd.to_datetime('2020-04-01 1:00'))
|
27
|
+
print(df)
|
28
|
+
"""
|
29
|
+
B
|
30
|
+
A
|
31
|
+
2020-04-01 01:00:00 1
|
32
|
+
2020-04-01 01:30:00 2
|
33
|
+
2020-04-01 02:00:00 3
|
34
|
+
"""
|
23
35
|
```
|