1

I have 4 Values data as output of a function. Here's my data

Name         Grade
usia         (75,78,90,52)
shdh         (85,68,60,72)
fbjg         (95,58,65,66)

Here's what I want

Name         Math    English   Physics    Chemistry
usia           75         78        90           52
shdh           85         68        60           72
fbjg           95         58        65           66
Nabih Bawazir
  • 5,275
  • 6
  • 29
  • 53

1 Answers1

1

Use DataFrame constructor with DataFrame.pop for remove original column Grade:

import ast

#if strings inputs instead tuples
#df['Grade'] = df['Grade'].apply(ast.literal_eval)

cols = ['Math','English','Physics','Chemistry']

df[cols] = pd.DataFrame(df.pop('Grade').tolist(), index=df.index)
print (df)
   Name  Math  English  Physics  Chemistry
0  usia    75       78       90         52
1  shdh    85       68       60         72
2  fbjg    95       58       65         66
jezrael
  • 729,927
  • 78
  • 1,141
  • 1,090