I'm trying to get the minimum increase between rows in a column in my table.
my attempt so far
import pandas as pd
df = pd.DataFrame({'A': [0, 100, 50, 100],
'B': [5, 2, 2, 0],
'C': [10, 20, 40, 400]})
def lowestIncrease(data, value):
table = data[value].pct_change().fillna(0)
x = data[value][table == table.min(i for i in table if i > 0)].index[0]
if x == 0:
print( 0 )
else:
answer = data[value][x] - data[value][x-1]
print( answer )
My idea to use min()
the way that that I am came from here https://stackoverflow.com/a/27966830/8705615
my desired output
in[1]:lowestIncrease(df, 'A')
out[1]:50
in[2]:lowestIncrease(df, 'B')
out[2]:0
in[3]:lowestIncrease(df, 'C')
out[3]:10
I feel like I'm close to what I'm trying to achieve, I just need to replace how I'm calling table.min(i for i in table if i > 0)
to get my desired output. How do you get the lowest change in value above 0 in a table?