Reputation: 880
I'm assigning a value to a specific pandas location. However, the value seems to slightly change for some reason. Does anyone know why this happens? I posted a snippet of my code below. I added the prints statements to see in more detail what happens, but it makes no sense to me.
if entry != None:
orders.iloc[index, orders.columns.get_loc('start_time_corrected')] = entry['t'].astype(np.int64)
print(entry['t'].astype(np.int64))
print(int(orders.iloc[index]['start_time_corrected']))
print(np.datetime64(int(orders.iloc[index]['start_time_corrected']),'ns'))
print(entry['t'])
which gives the following output:
1615606416410318537
1615606416410318592
2021-03-13T03:33:36.410318592
2021-03-13T03:33:36.410318537
as you can see the value in the output slightly changes, even though it should be the same value.
Upvotes: 0
Views: 78
Reputation:
There is a lost of casting from int
to numpy.int64
going on here and that is why you have a difference in values.
Because you are casting orders.iloc[index]['start_time_corrected']
to int
before you print it, you are going to lose information as python allocates 32-bits for for a normal integer type while numpy's np.int64
datatype is allocated 64 bits.
Upvotes: 1