My dataframe consists of the following table:
Time X Y 0100 5 9 0200 7 10 0300 11 12 0400 3 13 0500 4 14 My goal is to find the index of the value of Y which corresponds to a certain number (e.g.: 9) and return the corresponding X value from the table.
My idea previously was for a for-loop (as I have a number of Ys) to loop through and find all the values which match and then to create an empty array to store the values of X as such:
for i in (list of Ys): empty_storing_array.append(df[index_of_X].loc[df[Y] == i]) Problem is (if my newbie understanding of Pandas holds true), the values that loc gives is no number, but rather something else. How should I do it so that empty_storing_array then lists the numbers of X which corresponds to the values in array Y?
set_indextoYand useloc:df.set_index('Y').loc[9, 'X']