finding index to given value from dataset - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: finding index to given value from dataset (/thread-18586.html) |
finding index to given value from dataset - gamma - May-23-2019 So I have some data and I want to find out the index of the minimum. Since the data structure is not a list, I can't just use the list.index()command. I came up with the idea to loop through the data and if I find the minimum, I save the position. i = 0 q = 0 mini = data['open'].min() for x in data['open']: if x == mini: i = q q +=q print("index = ") print(i)When I run the program, I don't get any error but i = 0 what I don't understand since I found a minimum in the dataset with mini = data['open'].min(). Any idea whats going wrong here? RE: finding index to given value from dataset - heiner55 - May-26-2019 "q += q" should be: "q += 1" RE: finding index to given value from dataset - gamma - May-26-2019 Thanks a lot RE: finding index to given value from dataset - heiner55 - May-26-2019 You are welcome. |