I'm trying to extract values from array rows of a specific column with specified indices.
A dummy example, if I have a column called 'arr' in my dataframe where each array below is a row-
[1, 2, 3, 4, 5]
[6, 7, 8, 9, 10]
[11, 12, 13, 14, 15]
[16, 17, 18, 19, 20]
I've tried:
for row in df.itertuples():
i1 = [0,1,2]
r1 = np.array(df.arr)[i1]
i2 = [2,3]
r2 = np.array(df.arr)[i2]
which gives the rows 0, 1 and 2 from the dataframe.
And I've tried:
for row in df.itertuples():
i1 = [0,1,2]
r1 = np.array(row.arr)[i1]
i2 = [2,3]
r2 = np.array(row.arr)[i2]
which gives the values from only the last row. I don't understand why.
What I want to get are the indices specified in i1 and i2 as two different variables (r1 and r2) for each row. So-
r1 should give-
[1, 2, 3]
[6, 7, 8]
[11, 12, 13]
[16, 17, 18]
And r2 should give-
[3, 4]
[8, 9]
[13, 14]
[18, 19]
I've also used iterrows() with no luck.