Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

 How to fetch data from remote URL using JSON format and convert into numpy array?


to fetch data in JSON format, we will use the following library and method.


import json

import urllib.request

import numpy as np


data =  urllib.request.urlopen("https://shivaconceptsolution.com/webservices/showdriver.php");

s= json.loads(data.read())

arr1 = np.array([],dtype=int)

arr2 = np.array([],dtype=str)


#arr2 = np.array([''],dtype=str)





for d in s["result"]:

   arr3=np.append(arr1,d["id"])

   print(arr3)

   arr4=np.append(arr2,d["uname"])

   print(arr4) 

  

'''for d in s["result"]:    #to display individual data 

    for d1 in d:

        arr2=np.append(arr,d[0][d1])

        print(d1,d[d1],end='')

    print() '''

#print(arr1)

#print(arr2)

#print(arr)'''


'''data = urllib.request.urlopen("https://api.gdax.com/products/BTC-EUR/ticker")

s= json.loads(data.read()) # text to json conversion

print(s)

print(s['trade_id'])

for key in s:

    print(key,s[key])'''



Assignment:-

USE the SAME API to find max id, min id, avg id, repeated mobile number, null record rows, max null record rows.





5 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. # To Find Largest Element in the List
    data = urllib.request.urlopen("https://shivaconceptsolution.com/webservices/showdriver.php");

    s= json.loads(data.read())

    arr1 = np.array([],dtype=int)

    def Large(list1):
    m = list1[0]
    for x in list1:
    if x > m :
    m = x
    return m

    for d in s["result"]:

    arr3=np.append(arr1,d["id"])

    print(arr3)

    print("Largest element is:", Large(arr3))

    ReplyDelete
  2. # Data Science ( 6 To 7 Pm BATCH)
    # Finding Max Id, Avg Id, Repeated Mobile Number.

    import json

    import urllib.request

    import numpy as np



    data = urllib.request.urlopen("https://shivaconceptsolution.com/webservices/showdriver.php");

    s= json.loads(data.read())

    idd= 0

    b = 0

    av = 0

    lst = []

    for d in s["result"]:

    b+=1
    arr3=np.append(arr1,d["id"])

    print("ID. :-",arr3)

    arr4=np.append(arr2,d["uname"])

    print("User Name:-",arr4)

    arr5=np.append(arr2,d['emailid'])

    print("Email.ID:-",arr5)

    arr6=np.append(arr2,d['mobile'])

    print("Mobile No. :-",arr6,"\n")

    av = av+int(d["id"])

    lst.append(d['mobile'])


    if int(d["id"])>idd:
    idd = int(d["id"])

    print("Maximum ID :-",idd,"\n")
    print("Average ID :-",av/b)

    for d in s["result"]:
    mo = lst.count(d['mobile'])
    if mo>1:
    print(d,"Repeated :-",mo,"Times")





    ReplyDelete
  3. :- code for find repeted numbers in list
    #Jayant Chawliya

    lst=['12345','4567','12345','4567']
    s= set(lst)

    for d in s:
    c=lst.count(d)
    if c>1:
    print(d,"Repeted :-",c,"Times")

    ReplyDelete
  4. # Data Science ( 6 To 7 Pm Batch)

    # Code to find max id, avg id, repeated mobile number from URL.

    import json

    import urllib.request

    import numpy as np



    data = urllib.request.urlopen("https://shivaconceptsolution.com/webservices/showdriver.php");

    s= json.loads(data.read())

    idd= 0

    b = 0

    av = 0

    lst = []

    arr1 = np.array([],dtype=int)

    arr2 = np.array([],dtype=str)


    for d in s["result"]:

    b+=1
    arr3=np.append(arr1,d["id"])

    print("ID. :-",arr3)

    arr4=np.append(arr2,d["uname"])

    print("User Name:-",arr4)

    arr5=np.append(arr2,d['emailid'])

    print("Email.ID:-",arr5)

    arr6=np.append(arr2,d['mobile'])

    print("Mobile No. :-",arr6,"\n")

    av = av+int(d["id"])

    lst.append(d['mobile'])# All mobile no. Append in lst[]


    if int(d["id"])>idd:
    idd = int(d["id"])

    print("Maximum ID :-",idd,"\n")
    print("Average ID :-",av/b)


    # Code to Find Repeated Mobile No.
    lst1 = [] # For unique Mobile No.
    for i in lst:
    if i not in lst1:
    lst1.append(i)


    for d in s["result"]:
    mo = lst1.count(d['mobile'])
    if mo>1:
    print(d,"Repeated :-",mo,"Times")





    ReplyDelete
  5. # Excel Sheet "Record"
    #worksheet="A"
    #worksheet="B"
    #Combine Both A and B into python using openpyxl
    import openpyxl

    l1 = 0
    l2 = 1
    wb = openpyxl.load_workbook('Record.xlsx')
    sheets = wb.sheetnames
    ws = wb[sheets[l1]]
    print(ws)
    ws1 = wb[sheets[l2]]
    print(ws1)

    print("\n\nSheet 1 Data \n")
    ar =[]#Empty List
    col = ws.max_column
    ro = ws.max_row
    for i in range(1,(ro+1)):
    k=0
    ar1=[]#Empty List
    for j in range(1,(col+1)):
    c1 = ws.cell(row = i, column = j)
    ar1.append(c1.value)
    k+=1
    ar.append(ar1)
    arr = np.concatenate((ar))
    print(arr)
    print("\n")

    print("Sheet 2 Data \n")

    a =[]#Empty List
    col1 = ws1.max_column
    ro1 = ws1.max_row

    for k in range(1,(ro1+1)):
    k1=0
    ar2=[]#Empty List
    for p in range(1,(col1+1)):
    c12 = ws1.cell(row = k, column = p)
    ar2.append(c12.value)
    k1+=1
    a.append(ar2)
    arrr = np.concatenate((a))
    print(arrr)

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post