1
s.index=[0.0,1.1,2.2,3.3,4.4,5.5]
s.index
# Float64Index([0.0, 1.1, 2.2, 3.3, 4.4, 5.5], dtype='float64')
s
# 0.0    141.125
# 1.1    142.250
# 2.2    143.375
# 3.3    143.375
# 4.4    144.500
# 5.5    145.125
s.index=s.index.astype('float32')
# s.index
# Float64Index([              0.0, 1.100000023841858, 2.200000047683716,
#               3.299999952316284, 4.400000095367432,               5.5],
#              dtype='float64')

It looks like these 64-bit floats are getting cast to 32-bit floats and then back to 64-bit floats, since the dtype of the index remains 'float64'.

Appreciate any clarity on what's happening, and on the general intuitions behind index types for Pandas Series objects.

I was very surprised to learn you can have float indices! It seems like you can have three types of indices: int64, float64, or object (e.g. s.index=['a','b','c','d','e','f']).

How do people use float indicies?

phoenixdown
  • 828
  • 1
  • 10
  • 16

0 Answers0