我在下面编写的代码
try:
ser.isOpen()
print("Serial is Open")
except:
print("Eror")
exit()
if (ser.isOpen()):
ser.write('1'.encode('utf-8'))
df= pd.DataFrame(columns=['x-axis','y-axis','z-axis'])
while(1):
while(k<TIME_PERIODS):
Raw_data= ser.readline()
#print(Raw_data.decode('utf-8'))
Data= Raw_data.decode('utf-8').split(',')
df=df.append({'x-axis': Data[0],'y-axis': Data[1],'z-axis': Data[2]}, ignore_index=True)
df
k=k+1
k=0
df= pd.drop('x-axis','y-axis','z-axis',axis=1)
else :
print("cannot connect")
结果在这里
20 Data= Raw_data.decode('utf-8').split(',')
---> 21df=df.append({'x-axis': Data[0],'y-axis': Data[1],'z-axis': Data[2]}, ignore_index=True)
22 df
23 k=k+1
IndexError:列表索引超出范围
请帮助我修复它