is there any effective or efficient way to find net position of numbers from a data frame in python
Solution 1:
There is a simple formula that maps Turtle
to Net Pos
. The calculation can be expressed as a sum of geometric series times base_quantity, yielding the function f
below.
turtle_factor = 3
base_quantity = 2
def f(n):
return base_quantity * (turtle_factor ** n - 1) // (turtle_factor - 1)
df = pd.DataFrame({
"Turtle": [6, 2, 0, 4, 1, 2, 9],
})
df["Net Pos"] = f(df.Turtle)