Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pandas query on finding position in history

I want to find at which position the min price is there in the history data


def initialize(context):  
    context.security = symbol('SPY')  
    set_benchmark(symbol('SPY'))  
    schedule_function(func=trade, date_rule=date_rules.every_day(), time_rule=time_rules.market_open(minutes=1))  
    pass

def trade(context, data):  
    days = 7  
    dump = history(bar_count=(days), frequency='1d', field='price')  
    price_min = dump[context.security].min()  
    log.info(price_min)  
    #How do I find the N where N is Nth position of price_max ? in dump  
def handle_data(context, data):  
    pass  
2 responses

Ah located one way.

converted to list and checked the index.


def initialize(context):  
    context.security = symbol('SPY')  
    set_benchmark(symbol('SPY'))  
    schedule_function(func=trade, date_rule=date_rules.every_day(), time_rule=time_rules.market_open(minutes=1))  
    pass

def trade(context, data):  
    days = 7  
    dump = history(bar_count=(days), frequency='1d', field='price')  
    price_min = dump[context.security].min()  
    n = dump.values.tolist()  
    k = n.index([price_min])  
    log.info(k)  
    #How do i find the N where N is Nth position of price_max ?  
def handle_data(context, data):  
    pass

@Yagnesh - A better way is to use the Pandas .argmin() and .argmax() methods.