Reputation: 2220
I have a data frame that contains column time. The data type of time column is timedelta64[ns]
. The time column contains 0 days as a suffix. The time column looks like as follow:
df['time']:
0 days 00:00:00
0 days 00:30:00
0 days 01:00:00
0 days 01:30:00
0 days 02:00:00
I am trying to remove the 0 days from the column by following the existing thread (Remove the days in the timedelta object). However, it did not remove 0 days from the column. Could anyone guide me on how to get rid of 0 days from the timedelta64 datatype column?
Upvotes: 0
Views: 2250
Reputation: 153460
You can try something like this:
df['time'] = pd.Series([pd.Timedelta(minutes=i) for i in range(0,100,5)])
df['time'] = df['time'].astype(str).str.split('0 days ').str[-1]
df
Output:
time
0 00:00:00
1 00:05:00
2 00:10:00
3 00:15:00
4 00:20:00
5 00:25:00
6 00:30:00
7 00:35:00
8 00:40:00
9 00:45:00
10 00:50:00
11 00:55:00
12 01:00:00
13 01:05:00
14 01:10:00
15 01:15:00
16 01:20:00
17 01:25:00
18 01:30:00
19 01:35:00
Upvotes: 3