
# Import the requirements
import pyodata
import pandas as pd
import requests
# Create a PyOData client instance
service_url = "http://vhcalnplci.dummy.nodomain:8000//sap/opu/odata/sap/EPM_REF_APPS_SHOP_SRV"
#we are querying Shopping service to analyse the review information
session = requests.Session()
session.auth = ('Developer', 'Down1oad')
#username and password for ABAP developer edition
client = pyodata.Client(service_url, session)
# Get the Products entity set and its entity type
entity_sets = client.entity_sets
products_entity_set=""
scalar_properties = set()
for es in client.schema.entity_sets:
if es.name == "Reviews":
proprties = es.entity_type.proprties()
for prop in proprties:
if prop.name == 'ProductId' or prop.name == 'Rating' or prop.name == 'HelpfulCount':
scalar_properties.add(prop.name)
print(scalar_properties)
reviews = client.entity_sets.Reviews.get_entities().execute()
# Create an empty list to store the dictionaries for each reviews
review_list = []
# Loop through each review entity and create a dictionary
for review in reviews:
review_dict = {}
for property_name in scalar_properties:
review_dict[property_name] = getattr(review, property_name)
review_list.append(review_dict)
# Convert the list of dictionaries to a pandas DataFrame
df = pd.DataFrame(review_list)
df=df.sort_index()
df2= df.groupby('ProductId').sum()
print(df2)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
16 | |
5 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 |