0

I have a dataframe of 145 columns, one column is variable A and the rest are subsets of variable B. What I want is a new dataframe of two columns, A and B. I want to make sure all the B values in the new dataframe have the corresponding A values.

A simplified example of 'original' dataframe:

   A  B1  B2
0  1   6  11
1  2   7  12
2  3   8  13
3  4   9  14
4  5  10  15

And what I would like to achieve:

   A   B
0  1   6
1  2   7
2  3   8
3  4   9
4  5  10
5  1  11
6  2  12
7  3  13
8  4  14
9  5  15

I have tried to do it like this but have manage to only get the equivalent of B1 and A, the rest vanishes.

original_data = data[1:145]

filtered_data = pd.DataFrame(columns = ['A', 'B'])

columns = list(original_data)

for values in columns:
    for row in pressure_data:
        filtered_data["B"] = original_data[values]
        filtered_data["A"] = data['A']

I'd appreciate any tips/advice! Many thanks.

ShrutiTurner
  • 174
  • 2
  • 14

0 Answers0