[英](Python) How can I split a column with both date and time (e.g. 2019-07-02 00:12:32 UTC) into two separate columns?
[英]Python: how to separate time records(e.g. 2015-02-01 12:34:22) in to two different arrays
dataframe
如下:
1 2015-02-01 18:04:33
2 2015-02-01 12:28:15
3 2015-02-01 12:28:56
4 2015-02-01 00:45:08
5 2015-02-01 00:46:28
6 2015-02-01 00:59:56
7 2015-02-01 01:00:21
8 2015-02-01 01:00:21
9 2015-02-01 01:02:51
10 2015-02-01 01:02:51
11 2015-02-01 01:14:14
這些時間記錄(例如2015-02-01 01:02:51)在此數據幀中被視為單個數組,我想將其分為數據和小時,例如2015-02-01在數組中,並且01:00:21在另一個數組中。
df.info()顯示Int64Index:695366條目,0到695365數據列(共13列):URID 695366非空對象GPRS 632202非空對象datetime 695362非空對象
我嘗試在numpy
使用split
,但是沒有用。 所以我想知道是否還有其他方法可以解決?
如果您的dtype
是datetime
則可以使用.dt
訪問器來分隔列:
In [32]:
df['date'], df['time'] = df['datetime'].dt.date, df['datetime'].dt.time
df
Out[32]:
datetime date time
index
1 2015-02-01 18:04:33 2015-02-01 18:04:33
2 2015-02-01 12:28:15 2015-02-01 12:28:15
3 2015-02-01 12:28:56 2015-02-01 12:28:56
4 2015-02-01 00:45:08 2015-02-01 00:45:08
5 2015-02-01 00:46:28 2015-02-01 00:46:28
6 2015-02-01 00:59:56 2015-02-01 00:59:56
7 2015-02-01 01:00:21 2015-02-01 01:00:21
8 2015-02-01 01:00:21 2015-02-01 01:00:21
9 2015-02-01 01:02:51 2015-02-01 01:02:51
10 2015-02-01 01:02:51 2015-02-01 01:02:51
11 2015-02-01 01:14:14 2015-02-01 01:14:14
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.