I have a pandas DataFrame with the following structure:
And I have an array of tuples
arr_tuples = [(0,3),(1,1),(1,3),(2,1)]
Each tuple in the array represent the row and column index of the above dataframe respectively.
I can find all the values in the data frame for the indices in arr_tuples using for loop like this:
value_array = []
for item in arr_tuples:
row = item[0]
col = item[1]
value = df.iloc[row,col] # I also tried df.get_value here with similar result
value_array.append(value)
But this seems to be a very slow method. If there are a lot of tuples in my arr_tuples, this will take a long time.
Is there a better and faster way to achieve the same ? Is there any way in pandas where I can use a list/array of tuples (containing row and column index) to get values in a dataframe ?
