I have a list of tuples(y) that I wish to convert to a DataFrame x. There are five tuples in y. Each tuple in y has 33 elements. Element 1 in all 5 tuples is text and is the same. Element two in all five tuples is text and is the same. Element three in each tuple is text and is the same.
I'd like to first three elements in y to be the column names in the DataFrame. I want to convert the list of tuples into a 10 x 3 DataFrame. The tricky part is row 1 in the dataframe would be elements 4,5,6 in y[1], row 2 in the dataframe would be elements 7,8,9 in y[1], row 3 would be 10,11,12...etc.
y looks like this (not showing the entire list) :
List of tuples y
y[0] y[1] y[2] y[3] y[4]
Formula Formula Formula Formula Formula
Phase Phase Phase Phase Phase
Value Value Value Value Value
"a" "a" "a" "a" "a"
"nxxx" "nxxx" "nxxx" "nxxx" "nxxx"
3.2 3.7 22.4 18.2 9.7
"h45" "h45" "h45" "h45" "h45"
"cacpp" "cacpp" "cacpp" "cacpp" "cacpp"
45.2 61.76 101.2 171.89 203.7
"trx" "trx" "trx" "trx" "trx"
"v2o5p" "v2o5p" "v2o5p" "v2o5p" "v2o5p"
0.24 0.81 0.97 1.2 1.98
"blnt" "blnt" "blnt" "blnt" "blnt"
"g2o3" "g2o3" "g2o3" "g2o3" "g2o3"
807.2 905.8 10089 10345 10979
I want to convert y into DataFrame x as follows:
DataFrame x
column 1 column 2 column 3
Formula Phase Value
"a" "nxxx" 3.2
"h45" "cacpp" 45.2
"trx" "v2o5p" 0.24
"blnt" "g2o3" 807.2
"a" "nxxx" 3.7
"h45" "cacpp" 61.76
"trx" "v2o5p" 0.81
"blnt" "g2o3" 905.8
"a" "nxxx" 22.4
"h45" "cacpp" 101.2
"trx" "v2o5p" 0.97
"blnt" "g2o3" 10089
etc etc etc
I know there must be an easy way to iterate through the list of tuples. But new to Pandas and relatively new to Python so I'm struggling with a clean way to do this.