这似乎有效.可能有点清理代码.但是你得到了它的要点
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('v