我想根据数据框列内的字典值为数据框添加列
attendanceDetails |
---|
"[{' clockkin ': '1669435507', 'clockOut': '1669468193', 'actionBy': ", 'actionByName': ", 'actionById': ", 'actionRemark': ", 'actionByTimeStamp': None, 'deviceNameClockIn': '119', ' devicenumberclockkin ': ", ' devicelocationidclockkin ': ", 'deviceLocationClockOut': ", 'deviceLocationClockOut': ", 'deviceLocationClockOut': ", 'deviceLocationClockOut': ", 'deviceLocationClockOut': ", 'deviceLocationClockOut': ", 'deviceLocationClockOut': ", 'deviceLocationClockOut': ", 'deviceLocationClockOut': '8 '}]"> |
使用说明:
import ast
df = df.join(pd.json_normalize(df['attendanceDetails'].apply(ast.literal_eval).str[0]))
print (df)
attendanceDetails clockIn clockOut
0 [{'clockIn': '1669435507', 'clockOut': '166946... 1669435507 1669468193
actionBy actionByName actionById actionRemark actionByTimeStamp
0 None
deviceNameClockIn deviceNumberClockIn deviceLocationIdClockIn
0 119
deviceLocationClockIn deviceNameClockOut deviceNumberClockOut
0 8th
deviceLocationIdClockOut deviceLocationClockOut
0 8th