I have a list containing float values and I want to make a DataFrame out of it. But I am getting an error TypeError: 'float' object is not iterable
'''python
newlist = []
for i in path.toolpath:
newlist = [i.x, i.y,i.z, i.e, i.moveSpd]
labels = ['x_coordinate' , 'y_coordinate', 'z_coordinate', 'e', 'speed']
df1 = pd.DataFrame.from_records(newlist, columns = labels)
print(df1)
'''
A part of newlist is as follows.
[-40.8629, 2.28, 44.3492, 1698.7625, 300]
[-40.788, 2.28, 43.352, 1699.0625, 300]
[-40.7131, 2.28, 42.3548, 1699.3625, 300]
[-40.6382, 2.28, 41.3576, 1699.6625, 300]
[-40.5633, 2.28, 40.3604, 1699.9625, 300]
your new_list variable is getting overwritten, you need to append the value. Like this
newlist = []
for i in path.toolpath:
temp = [i.x, i.y,i.z, i.e, i.moveSpd]
new_list.append(temp)
labels = ['x_coordinate' , 'y_coordinate', 'z_coordinate', 'e', 'speed']
df1 = pd.DataFrame(newlist, columns = labels)
print(df1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.