日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python时间序列进行线性插值_Python pandas时间序列插值日期时间数据

發布時間:2024/7/19 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python时间序列进行线性插值_Python pandas时间序列插值日期时间数据 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這似乎有效.可能有點清理代碼.但是你得到了它的要點

from datetime import datetime

import pandas as pd

import time

#Create data

df = pd.DataFrame({ 'interval' : [0.782296, 0.795469, 0.821426, 0.834957,

0.864383, 0.906240],

'datetime' : [datetime(2012, 11, 19, 12, 40, 10), pd.NaT,

datetime(2012, 11, 19, 12, 35, 10), pd.NaT,

datetime(2012, 11, 19, 12, 30, 10),

datetime(2012, 11, 19, 12, 25, 10)

]})

#Cast date to seconds (also recast the NaT to Nan)

df['seconds'] = [time.mktime(t.timetuple()) if t is not pd.NaT else float('nan') for t in df['datetime'] ]

#Set the interval as the index, as interpolation uses the index

df.set_index('interval', inplace=True)

#Use the 'values'-argument to actually use the values of the index and not the spacing

df['intepolated'] = df['seconds'].interpolate('values')

#Cast the interpolated seconds back to datetime

df['datetime2'] = [datetime.utcfromtimestamp(t) for t in df['intepolated']]

#Clean up

df.reset_index(inplace=True)

df = df[['interval', 'datetime2']]

>>>>df

Out[25]:

interval datetime2

0 0.782296 2012-11-19 11:40:10.000000

1 0.795469 2012-11-19 11:38:29.005878

2 0.821426 2012-11-19 11:35:10.000000

3 0.834957 2012-11-19 11:33:35.503178

4 0.864383 2012-11-19 11:30:10.000000

5 0.906240 2012-11-19 11:25:10.000000

希望這是你想要的.

總結

以上是生活随笔為你收集整理的python时间序列进行线性插值_Python pandas时间序列插值日期时间数据的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。