I wanted to know if it's possible to stack columns values from the same data frame with almost the same name. I have the following data frame
import pandas as pd
data = {'text':['hello','hi'],
'a':[1,2,],
'b':[2,1,],
'a.1':[3,4],
'b.1':[4,3]
}
I have multiple a. and b. so it goes to a.N and b.N but the end result has to be like the below data frame.
data2 ={'text':['hello','hi','hello','hi'],'identifier':[0,0,1,1],
'a':[1,2,3,4],
'b':[2,1,4,3],
}
the identifier column is just to know how it was stacked for instance the first 2 values 0,0 came from the original column and 1,1 came from a.1 and b.1. I hope it all makes sense.