Python Forum
DataFrame simple calculation - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: DataFrame simple calculation (/thread-14250.html)



DataFrame simple calculation - SamSoftwareLtd - Nov-21-2018

Hi,

I'm unsure if this is a normal or strange result I'm getting in the below simple DataFrame contains 5 elements of floats stock prices, with their Date as the index, if I apply plus operator, the result is right with 6 decimals, but if I apply divide or substract I receive only 1 decimals and not sure if the result is right, can someone please shed the light/explain why, or otherwise how to get 6 fractions when I apply divide:
print(cl)
Out[45]:
Date
2017-01-03 167.190002
2017-01-04 169.259995
2017-01-05 168.699997
2017-01-06 169.529999
2017-01-09 167.649994
Freq: B, Name: Close, dtype: float64
cl[1:]/cl[:-1]
Out[46]:
Date
2017-01-03 NaN
2017-01-04 1.0
2017-01-05 1.0
2017-01-06 1.0
2017-01-09 NaN
Freq: B, Name: Close, dtype: float64
cl[1:]+cl[:-1]
Out[47]:
Date
2017-01-03 NaN
2017-01-04 338.519990
2017-01-05 337.399994
2017-01-06 339.059998
2017-01-09 NaN
Freq: B, Name: Close, dtype: float64
cl[1:]-cl[:-1]
Out[48]:
Date
2017-01-03 NaN
2017-01-04 0.0
2017-01-05 0.0
2017-01-06 0.0
2017-01-09 NaN
Freq: B, Name: Close, dtype: float64