danfo.to_datetime
Converts an array of Date time string to Date object.
danfo.to_datetime(data) [source]
Parameters
Type
Description
Default
data
Array, Series
data: Array | Series with Date strings to convert to Date time.
Returns:
return DataFrame

Examples

Converts a Series of Date strings to Date time and get time properties
Node
Browser
1
let data = new dfd.date_range({"start":'1/1/2018',period:12, freq:'M'})
2
let sf = new dfd.Series(data)
3
sf.print()
4
5
let dt = dfd.toDateTime(data)
6
7
dt.month().print()
8
dt.month_name().print()
9
dt.weekdays().print()
10
dt.day().print()
11
dt.seconds().print()
Copied!
1
Copied!
Output
1
0
2
0 1/1/2018, 12:00:00 AM
3
1 2/1/2018, 12:00:00 AM
4
2 3/1/2018, 12:00:00 AM
5
3 4/1/2018, 12:00:00 AM
6
4 5/1/2018, 12:00:00 AM
7
5 6/1/2018, 12:00:00 AM
8
6 7/1/2018, 12:00:00 AM
9
7 8/1/2018, 12:00:00 AM
10
8 9/1/2018, 12:00:00 AM
11
9 10/1/2018, 12:00:00 AM
12
10 11/1/2018, 12:00:00 AM
13
11 12/1/2018, 12:00:00 AM
14
15
//Int representation for month
16
0
17
0 0
18
1 1
19
2 2
20
3 3
21
4 4
22
5 5
23
6 6
24
7 7
25
8 8
26
9 9
27
10 10
28
11 11
29
30
//string representation for month
31
0
32
0 Jan
33
1 Feb
34
2 Mar
35
3 Apr
36
4 May
37
5 Jun
38
6 Jul
39
7 Aug
40
8 Sep
41
9 Oct
42
10 Nov
43
11 Dec
44
45
//string representation for day of the week
46
0
47
0 Mon
48
1 Thur
49
2 Thur
50
3 Sun
51
4 Tue
52
5 Fri
53
6 Sun
54
7 Wed
55
8 Sat
56
9 Mon
57
10 Thur
58
11 Sat
59
60
0
61
0 1
62
1 4
63
2 4
64
3 0
65
4 2
66
5 5
67
6 0
68
7 3
69
8 6
70
9 1
71
10 4
72
11 6
73
74
//Hour of the day
75
0
76
0 0
77
1 0
78
2 0
79
3 0
80
4 0
81
5 0
82
6 0
83
7 0
84
8 0
85
9 0
86
10 0
87
11 0
88
Copied!
Date time properties of Series or datetime-like columns in DataFrame can be accessed via accessors in the dt name-space. See Accessors
Last modified 15d ago
Copy link
Contents
Examples