List to dataframe conversion

Question:

Having data as below:

my_list=[(B_BC,0.3140561085683502, 0.27612272457883213)
(BR_BR,0.1968307181527823, 0.18806346643096217)]

I need to convert this to data frame with 3 column. First Column with location and second and third column should be a and b.

Expected Output

Expected

Asked By: Unicorn

||

Answers:

I am assuming you are using Python, then this would work:

my_list = [('B_BC',0.3140561085683502, 0.27612272457883213),
('BR_BR',0.1968307181527823, 0.18806346643096217)]
   
import pandas as pd

df = pd.DataFrame(my_list, columns = ['Location','A','B'])

print(df)

Location       A         B
  B_BC     0.314056  0.276123
  BR_BR    0.196831  0.188063
Answered By: Vinícius Félix
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.