1

so I have pandas dataframe and an array. The dataframe and array look like this:

In [1]:

d = {'A1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],  
'B1': [0.132, 0.234, 0.564, 0.354, 0.132, 0.234, 0.564, 0.354, 0.354, 0.132, 0.234, 0.564, 0.354, 0.354],  
'B2': [0.121, 0.675, 0.324, 0.343, 0.121, 0.675, 0.324, 0.343, 0.343, 0.121, 0.234, 0.564, 0.354, 0.354],  
'B3': [0.453, 0.788, 0.343, 0.666, 0.453, 0.788, 0.343, 0.666, 0.666, 0.453, 0.234, 0.564, 0.354, 0.354],  
'C1': [0.243, 0.121, 0.675, 0.354, 0.243, 0.121, 0.675, 0.354, 0.354, 0.243, 0.234, 0.564, 0.354, 0.354],  
'C2': [0.243, 0.777, 0.463, 0.677, 0.243, 0.777, 0.463, 0.677, 0.677, 0.243, 0.234, 0.564, 0.354, 0.354],   
'C3': [0.433, 0.132, 0.234, 0.564, 0.433, 0.132, 0.234, 0.564, 0.564, 0.433, 0.234, 0.564, 0.354, 0.354]}

In [2]:df = pd.DataFrame(data=d)

In [3]:
A = pd.array([1, 4, 9, 2, 5, 10])

I would like to subset the column B1 - D3 based on the array A: by matching the value of array A to column A1. So each row in array A sets the subset point for each column in the table; hence, the length of array A is the same as the number of columns in the table (excluding column A1). Keep in mind, that the real value of A and A1 are not whole number, but decimals.

Note: this might be irrelevant information, but the data is a cycle. Cycle 1: B1 - B3, Cycle 2: C1-C3, etc.

This is the desired result: enter image description here

If you need more information, let me know. If anyone could help me, I would be very grateful. Thank you so much.

MaryJane
  • 23
  • 4

0 Answers0