Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:从时间列中删除0天后缀_Python_Python 3.x_Pandas - Fatal编程技术网

Python:从时间列中删除0天后缀

Python:从时间列中删除0天后缀,python,python-3.x,pandas,Python,Python 3.x,Pandas,我有一个包含列时间的数据帧。时间列的数据类型为timedelta64[ns]。时间列包含0天作为后缀。时间列如下所示: 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 我正试图通过遵循现有线程()从列中删除0天。但是,它没有从列中删除0天。有谁能告诉我如何从timedelta64数据类型列中删除0天吗?您可以尝试以下方法: df['time'] = pd.S

我有一个包含列时间的数据帧。时间列的数据类型为
timedelta64[ns]
。时间列包含0天作为后缀。时间列如下所示:

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

我正试图通过遵循现有线程()从列中删除0天。但是,它没有从列中删除0天。有谁能告诉我如何从timedelta64数据类型列中删除0天吗?

您可以尝试以下方法:

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
输出:

        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

您可以尝试以下方法:

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
输出:

        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

这回答了你的问题吗?这回答了你的问题吗?