1

I would like to flatten a dictionary that is inside the dataframe. Below is my data:

import pandas as pd
data = {'ID': [0,1],
        'Name': ['Lucas', 'Benjamin'],
        'Records': [{'Date':'2022-05-19', 'TimeIn': '7:00', 'TimeOut': '15:00'},
                    {'Date':'2022-05-19', 'TimeIn': '8:00', 'TimeOut': '14:00'}]}
sample = pd.DataFrame(data)

I want my output to be:

ID  Name      Date          TimeIn    TimeOut
0   Lucas     2022-05-19    7:00      15:00
1   Benjamin  2022-05-19    8:00      14:00
wjandrea
  • 28,235
  • 9
  • 60
  • 81
ACRS
  • 11
  • 2

1 Answers1

0

Do this,

pd.concat([df.drop(columns="Records"), pd.DataFrame(df["Records"].tolist())], axis=1)
Zero
  • 1,800
  • 1
  • 5
  • 16