interpolate函数问题

运行会报错,后来发现是采集时间这一列的问题,看来一下是datatime类型,想着改成数字类型就不会报错,便加了第3行。其他列的运行倒是没问题了,但采集时间这一列全变成了空值,大家有知道这是什么原因吗?还有下面的报错又是为啥?

import pandas as pd
df=pd.read_excel(r"111.xls")
df['采集时间'] = df['采集时间'].apply(pd.to_numeric,errors='coerce')
df1 = pd.DataFrame(df)
 df2=df1.interpolate()
df2.to_excel(r"1.xls")
print(df2)

没有第3行会报错,如下


ValueError: Invalid fill method. Expecting pad (ffill) or backfill (bfill). Got linear

你试试不转数值,转成datetime类型呢,应该也能内插

df['采集时间'] = pd.to_datetime(df['采集时间'])
df1 = pd.DataFrame(df)
df2 = df1.interpolate(method='linear')