我通过从csv文件中读取数据帧来在Pandas中创建数据帧。 数据框包含多个浮点值。 当我使用itertuples遍历我的数据帧时,一个浮点值从2.3变为2.2999999999999998。 首先我认为这可能会发生,因为数据格式从数据帧变为元组,但值在数据帧和元组中都存储为float。
所以我的问题是:为什么会这样?
print(dfAll)
speed=dfAll['speed']
for value in motion:
print(type(value))
for t in dfAll.itertuples():
print(type(t.speed))
print(t)
phase motion speed attention shape_speed shape_combination fail
0 1 80 1.7 90 up up 0
1 1 89 1.5 85 same same 0
2 1 75 2.3 75 down down 0
3 1 82 2.5 80 same same 0
4 1 30 0.0 0 0 0 1
<type 'numpy.float64'>
<type 'numpy.float64'>
<type 'numpy.float64'>
<type 'numpy.float64'>
<type 'numpy.float64'>
<type 'numpy.float64'>
Pandas(Index=0, phase=1, motion=80, speed=1.7, attention=90, shape_speed=u'up', shape_combination=u'up', fail=0)
<type 'numpy.float64'>
Pandas(Index=1, phase=1, motion=89, speed=1.5, attention=85, shape_speed=u'same', shape_combination=u'same', fail=0)
<type 'numpy.float64'>
Pandas(Index=2, phase=1, motion=75, speed=2.2999999999999998, attention=75, shape_speed=u'down', shape_combination=u'down', fail=0)
<type 'numpy.float64'>
Pandas(Index=3, phase=1, motion=82, speed=2.5, attention=80, shape_speed=u'same', shape_combination=u'same', fail=0)
<type 'numpy.float64'>
Pandas(Index=4, phase=1, motion=30, speed=0.0, attention=0, shape_speed=u'0', shape_combination=u'0', fail=1)