I have an issue. As you see the following example:
JavaScript
x
4
1
data = pd.DataFrame({'a':[127093342616], 'b':[22853943721]})
2
data['a*b']= data['a']*data['b']
3
data
4
- When I multiply 2 numbers: 127093342616 vs 22853943721, the result = 2904584099459834914136
- But, when I use DataFrame of pandas and multiply the 2 columns the result = 8445279887435310424
Can anybody tell me the reason this occurs and a solution?
Advertisement
Answer
Try using float datatype, you’re having integer overflow problems:
JavaScript
1
4
1
data = pd.DataFrame({'a':[127093342616], 'b':[22853943721]}, dtype=np.float)
2
data['a*b']= data['a']*data['b']
3
data
4
Output:
JavaScript
1
3
1
a b a*b
2
0 1.270933e+11 2.285394e+10 2.904584e+21
3
Because pandas use numpy underneath, let’s look at numpy datatypes.
numpy.int64 – Integer (-9223372036854775808 to 9223372036854775807)