aditya
aditya

Reputation: 55

Iterating over multiple dictionary and saving the data in dataframe

I receive data from a SharePoint List in a form dictionary. Each List row is retrieved as a dictionary .I want to create a data frame from that data.

Sample Data -:

   {'__metadata': {'id': 'b50ca1d6-0932-4c09-ad76-122c1c77b9a1', 'uri': 
   "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
   81fb1b5319ca')/Items(227)", 'etag': '"1"', 'type': 
   'SP.Data.EMM_x0020_Testing_x0020_ListListItem'}, 'FirstUniqueAncestorSecurableObject': 
   {'__deferred': {'uri': 
   "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
   81fb1b5319ca')/Items(227)/FirstUniqueAncestorSecurableObject"}}, 'RoleAssignments': 
   {'__deferred': {'uri': 
   "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
    81fb1b5319ca')/Items(227)/RoleAssignments"}}, 'AttachmentFiles': {'__deferred': {'uri': 
   "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
    81fb1b5319ca')/Items(227)/AttachmentFiles"}}, 'ContentType': {'__deferred': {'uri': 
    "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
    81fb1b5319ca')/Items(227)/ContentType"}}, 'GetDlpPolicyTip': {'__deferred': {'uri': 
    "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
     81fb1b5319ca')/Items(227)/GetDlpPolicyTip"}}, 'FieldValuesAsHtml': {'__deferred': {'uri': 
    "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
    81fb1b5319ca')/Items(227)/FieldValuesAsHtml"}}, 'FieldValuesAsText': {'__deferred': 
   {'uri': "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d- 
     983b-81fb1b5319ca')/Items(227)/FieldValuesAsText"}}, 'FieldValuesForEdit': {'__deferred': 
    {'uri': "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d- 
    983b-81fb1b5319ca')/Items(227)/FieldValuesForEdit"}}, 'File': {'__deferred': {'uri': 
    "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
     81fb1b5319ca')/Items(227)/File"}}, 'Folder': {'__deferred': {'uri': 
     "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
   81fb1b5319ca')/Items(227)/Folder"}}, 'LikedByInformation': {'__deferred': {'uri': 
  "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
   81fb1b5319ca')/Items(227)/LikedByInformation"}}, 'ParentList': {'__deferred': {'uri': 
   "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
   81fb1b5319ca')/Items(227)/ParentList"}}, 'Properties': {'__deferred': {'uri': 
   "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
   81fb1b5319ca')/Items(227)/Properties"}}, 'Versions': {'__deferred': {'uri': 
   "https://test.sharepoint.com/sites/testing/_api/Web/Lists(guid'50c5c591-a269-435d-983b- 
   81fb1b5319ca')/Items(227)/Versions"}}, 'FileSystemObjectType': 0, 'Id': 227, 
  'ServerRedirectedEmbedUri': None, 'ServerRedirectedEmbedUrl': '', 'ID': 227, 
  'ContentTypeId': '0x0100F8C3471FC3D75645BA00614C809D5215', 'Title': 'X', 'Modified': '2021- 
   08-25T16:38:22Z', 'Created': '2021-08-25T16:38:22Z', 'AuthorId': 1073741822, 'EditorId': 
   1073741822, 'OData__UIVersionString': '1.0', 'Attachments': False, 'GUID': '05c0c733-73ff- 
   4bae-a8c4-1a5ddfefb0b7', 'ComplianceAssetId': None, 'Owner_x0020_Name': 'X', 'Application': 
   'Shared NUID', 'Attribute': 'SHARED_ID', 'Total_x0020_User_x0020_Count': '321.0'}

 

###################################################################################

My Code to read the SharePoint list and get the dictionary.

  def demo_list():
    print("**************\nList ...\n")
    items_dict = sp.get_items()
    for item in items_dict:
         print(type(item))

Upvotes: 0

Views: 37

Answers (1)

not_speshal
not_speshal

Reputation: 23146

Try with pandas.json_normalize:

df = pd.json_normalize(data, meta="_metadata")

Upvotes: 1

Related Questions