1 回答

TA貢獻2021條經驗 獲得超8個贊
all_contacts 變量是一個類似字典的元素列表。因此,為了創建數據框,我使用列表理解來創建一個元組,該元組僅包含每個類似字典的元素的“屬性”。
import datetime
import pandas as pd
from dateutil.tz import tzutc
data = ({'archived': False,
'archived_at': None,
'associations': None,
'created_at': datetime.datetime(2019, 12, 21, 17, 56, 24, 739000, tzinfo=tzutc()),
'id': 'xxx',
'properties': {'createdate': '2019-12-21T17:56:24.739Z',
'email': '[email protected]',
'firstname': 'John',
'hs_object_id': 'xxx',
'lastmodifieddate': '2020-04-22T04:37:40.274Z',
'lastname': 'Hansen'},
'updated_at': datetime.datetime(2020, 4, 22, 4, 37, 40, 274000, tzinfo=tzutc())},
{'archived': False,
'archived_at': None,
'associations': None,
'created_at': datetime.datetime(2019, 12, 21, 17, 52, 38, 485000, tzinfo=tzutc()),
'id': 'bbb',
'properties': {
'createdate': '2019-12-21T17:52:38.485Z',
'email': '[email protected]',
'firstname': 'John2',
'hs_object_id': 'bbb',
'lastmodifieddate': '2020-05-19T07:18:28.384Z',
'lastname': 'Hansen2'},
'updated_at': datetime.datetime(2020, 5, 19, 7, 18, 28, 384000, tzinfo=tzutc())})
df = pd.DataFrame([row['properties'] for row in data])
print(df)
輸出:
createdate email ... lastmodifieddate lastname
0 2019-12-21T17:56:24.739Z [email protected] ... 2020-04-22T04:37:40.274Z Hansen
1 2019-12-21T17:52:38.485Z [email protected] ... 2020-05-19T07:18:28.384Z Hansen2
[2 rows x 6 columns]
添加回答
舉報