Pandas 未来警告:不推荐将datetime64数据类型数据传递给TimedeltaIndex

Pandas 未来警告:不推荐将datetime64数据类型数据传递给TimedeltaIndex,pandas,typeerror,deprecated,datetime64,Pandas,Typeerror,Deprecated,Datetime64,我有一个测量值的数据集及其相应的时间戳,格式为hh:mm:ss,其中hh可以大于24小时 对于机器学习任务,数据需要插值,因为有多个测量值分别具有不同的时间戳。 对于重采样和插值,我指出索引的数据类型应该是datetime格式。 对于进一步的数据处理和机器学习任务,我需要再次使用timedelta格式 下面是一些代码: Res_cont = Res_cont.set_index('t_a') #t_a is the column of the timestamps for the measure

我有一个测量值的数据集及其相应的时间戳,格式为hh:mm:ss,其中hh可以大于24小时

对于机器学习任务,数据需要插值,因为有多个测量值分别具有不同的时间戳。 对于重采样和插值,我指出索引的数据类型应该是datetime格式。 对于进一步的数据处理和机器学习任务,我需要再次使用timedelta格式

下面是一些代码:

Res_cont = Res_cont.set_index('t_a') #t_a is the column of the timestamps for the measured variable a from a dataframe

#Then, I need to change datetime-format for resampling and interpolation, otherwise timedate are not like 00:15:00, but like 00:15:16 for example
Res_cont.index = pd.to_datetime(Res_cont.index) 

#first, upsample to seconds, then interpolate linearly and downsample to 15min steps, lastly  
Res_cont = Res_cont.resample('s').interpolate(method='linear').resample('15T').asfreq().dropna()

Res_cont.index = pd.to_timedelta(Res_cont.index) #Here is, where the error ocurred
不幸的是,我收到以下错误消息:

FutureWarning:无法将datetime64数据类型数据传递给TimedeltaIndex 已弃用,将在将来的版本Res_cont中引发TypeError= pd.至时间增量(资源控制索引)

很明显,我提供的代码的最后一行有问题。我想知道,如何更改此代码以防止在将来的版本中出现类型错误。不幸的是,我不知道如何修复它

也许你能帮忙

编辑:以下是一些任意示例数据:

t_a = ['00:00:26', '00:16:16', '00:25:31', '00:36:14', '25:45:44']
a = [0, 1.3, 2.4, 3.8, 4.9]
Res_cont = pd.Series(data = a, index = t_a)
您可以使用将输出日期时间转换为
HH:MM:SS
格式:

t_a = ['00:00:26', '00:16:16', '00:25:31', '00:36:14', '00:45:44'] 
a = [0, 1, 2, 3, 4] 

Res_cont = pd.DataFrame({'t_a':t_a,'a':a})
print (Res_cont)
        t_a  a
0  00:00:26  0
1  00:16:16  1
2  00:25:31  2
3  00:36:14  3
4  00:45:44  4

Res_cont = Res_cont.set_index('t_a') 
Res_cont.index = pd.to_datetime(Res_cont.index) 
Res_cont=Res_cont.resample('s').interpolate(method='linear').resample('15T').asfreq().dropna()
Res_cont.index = pd.to_timedelta(Res_cont.index.strftime('%H:%M:%S'))
print (Res_cont)
                 a
00:15:00  0.920000
00:30:00  2.418351
00:45:00  3.922807

不幸的是,这是不可能的。正如我在请求中所写的,在我的例子中,日期时间索引对于重采样和插值是必需的。我试图在代码的注释中指定这一点:>然后,我需要更改重新采样和插值的日期时间格式,>否则,时间日期与00:15:00不同,而与00:15:16相同example@MaxK. - 你能创建一些样本数据吗?我在我的原始文档的“编辑”下添加了一些样本数据post@MaxK. - 谢谢,更改了解决方案。@MaxK.-你的熊猫版本是什么?