df=pd.read_csv('E:/车辆轨迹数据-8月/080201/64896735341-20210719.csv')
col=df.columns.values
df.columns=[x.strip() for x in col] ###首行文字去前后空格
df.drop_duplicates(subset=['gpstime'],keep='first',inplace=True) ##删除gps时间重复的列
####数据预处理—————排序
df_paixu=df.sort_values(by=['gpstime'],ascending=[1])
df_paixu=df_paixu.reset_index(drop=True) ###重置排序后数列的index
df_paixu['gpstime']=(df_paixu['gpstime']-min(df_paixu['gpstime']))/1000#时间单位为s
#####数据预处理————数据单位转化为标准单位及百分比
df_paixu['speed']=(df_paixu['speed'])/100/3.6 #车速单位km/h
def v(vt):
l=df_paixu['speed']
for i in vt:
if i<=3.6:
l.append(0)
elif i<=7.2:
l.append(7.2-(7.2/(7.2-3.6))*(7.2-i))
else:
l.append(i)
return l
def fun(t):
Vc = df_paixu['speed']
for i in Vc:
if 0 < t < len(i) - 1: # len()函数返回对象(字符、列表、元组等)长度或项目个数。
if i[t - 1] + i[t + 1] == 0:
return 0
elif 1 < t < len(i) - 2:
if i[t - 2] + i[t + 2] == 0:
return 0
else:
return i[t]
from scipy.signal import savgol_filter
y = savgol_filter(df_paixu['speed'], 5, 1, mode= 'nearest')
a0=np.array(y,dtype=np.float64)
a=df.loc[500:1000,a0]#选取speed列的1-500行
print(a)
##画图
plt.plot(a,color='r', label=u'1路') # 绘制x,y的折线图
plt.savefig(r'C:\Users\歪歪\Desktop\工况预估\1.jpg')#保存图片
plt.show() # 显示折线图
报错: