Issue
This is my function
def price_to_ephe(data):
converted = []
for i in data:
while i >= 360:
i = i - 360
converted.append (i)
return converted
it makes every number less than 360. I want to apply it to column in dataframe.
2009-01-01, 886.0
2009-01-02, 884.2
2009-01-03, 882.1
2009-01-04, 882.6
2009-01-05, 883.4
2009-01-06, 889.1
2009-01-07, 887.6
2009-01-08, 882.5
2009-01-09, 879.7
2009-01-10, 878.3
2009-01-11, 876.6
2009-01-12, 875.2
Expected output:
2009-01-01, 166.0
2009-01-02, 164.2
..............
...and so on. Numbers can be large and small: 10000 and 20.
Help me please to do it in most efficient way. DataFrame is very large. I need all speed of pandas!
Solution
What you want is to get the modulo of your value, which is achieved with mod
(or %
):
df['modulo'] = df['value'].mod(360)
Or:
df['modulo'] = df['value'] % 360
Output:
date value modulo
0 2009-01-01 886.0 166.0
1 2009-01-02 884.2 164.2
2 2009-01-03 882.1 162.1
3 2009-01-04 882.6 162.6
4 2009-01-05 883.4 163.4
5 2009-01-06 889.1 169.1
6 2009-01-07 887.6 167.6
7 2009-01-08 882.5 162.5
8 2009-01-09 879.7 159.7
9 2009-01-10 878.3 158.3
10 2009-01-11 876.6 156.6
11 2009-01-12 875.2 155.2
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.