Python Forum
DataFrame simple calculation
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DataFrame simple calculation
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dataframe mean calculation problem: do we have to loop? sparkt 1 2,135 Aug-28-2020, 02:41 PM
Last Post: sparkt
  Iterate through all files in a folder and make simple calculation danielappleton 2 2,267 Apr-01-2020, 09:57 AM
Last Post: danielappleton
  Do Calculation between Rows based on Column values - Pandas Dataframe ahmedwaqas92 0 2,111 Jan-28-2020, 07:06 AM
Last Post: ahmedwaqas92
  Problem with simple 3D Vektor calculation Pythocodras 0 1,682 Dec-11-2019, 07:18 PM
Last Post: Pythocodras

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020