回答編集履歴
2
変更ミス修正
test
CHANGED
@@ -5,6 +5,16 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
```python
|
8
|
+
|
9
|
+
>>> def dt2hour(dt):
|
10
|
+
|
11
|
+
... d, t = dt.split()
|
12
|
+
|
13
|
+
... td = datetime.datetime.strptime(t, '%H:%M:%S.%f')-datetime.datetime(1900, 1, 1)
|
14
|
+
|
15
|
+
... return int(d)*24 + (td.seconds + td.microseconds/1000000)/3600
|
16
|
+
|
17
|
+
...
|
8
18
|
|
9
19
|
>>> df = pd.DataFrame({'day_time':['1 12:40:14.39', '2 08:25:31.18', '0 14:11:15.27', '40 8:43:39.95']})
|
10
20
|
|
1
誤り修正
test
CHANGED
@@ -1,3 +1,49 @@
|
|
1
|
+
日数が0の場合にエラーになるので修正しました。
|
2
|
+
|
3
|
+
0日でも32日以上でも動作します。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```python
|
8
|
+
|
9
|
+
>>> df = pd.DataFrame({'day_time':['1 12:40:14.39', '2 08:25:31.18', '0 14:11:15.27', '40 8:43:39.95']})
|
10
|
+
|
11
|
+
>>> print(df)
|
12
|
+
|
13
|
+
day_time
|
14
|
+
|
15
|
+
0 1 12:40:14.39
|
16
|
+
|
17
|
+
1 2 08:25:31.18
|
18
|
+
|
19
|
+
2 0 14:11:15.27
|
20
|
+
|
21
|
+
3 40 8:43:39.95
|
22
|
+
|
23
|
+
>>> df['hours'] = df['day_time'].apply(dt2hour)
|
24
|
+
|
25
|
+
>>> print(df)
|
26
|
+
|
27
|
+
day_time hours
|
28
|
+
|
29
|
+
0 1 12:40:14.39 36.670664
|
30
|
+
|
31
|
+
1 2 08:25:31.18 56.425328
|
32
|
+
|
33
|
+
2 0 14:11:15.27 14.187575
|
34
|
+
|
35
|
+
3 40 8:43:39.95 968.727764
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
以下は間違っていたので忘れてください。
|
44
|
+
|
45
|
+
|
46
|
+
|
1
47
|
多少技巧的ですが、以下で出来ます。
|
2
48
|
|
3
49
|
|