التخطي إلى المحتوى الرئيسي

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


Python provides JSON Module to read JSON data and urlib.request module to fetch data from remote URL?

This is the example to fetch records from JSON File.

Solution:-

import json

import urllib.request

import numpy as np

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

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

#print(s)

arr1 = []

arr2 = []

for k in s['result']:

    arr1.append(k['id'])

    arr2.append(k['uname'])

      # print(k['id'],k['uname'])

    print(arr1, arr2) 

a = np.array(arr1)

b = np.array(arr2)

print(a,b)

Assignment:-

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

2) Use Covid LIVE API and Provide Current Status, Country-wise, State-wise?



تعليقات

  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))

    ردحذف
  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")





    ردحذف
  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")

    ردحذف
  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")





    ردحذف
  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)

    ردحذف
  6. import json
    import urllib.request
    import numpy as np
    data = urllib.request.urlopen("https://shivaconceptsolution.com/webservices/showdriver.php");
    s= json.loads(data.read())
    l=[]
    l1=[]
    l2=[]
    l3=[]
    l4=[]
    for i in s["result"]:
    for j in i:

    l4.append(i[j])
    l.append(int(i.get("id")))
    l1.append(i.get("uname"))
    l2.append(i.get("emailid"))
    l3.append(i.get("mobile"))
    print("max id:",max(l))
    print("min id:",min(l))
    print("average id:",sum(l)/len(l))
    for i in l3:
    b=l3.count(l3)
    l8=[]
    print("repeated mobile no.",b)
    co=0
    m=0
    for i in range(0,len(l4),9):
    c=l4[0+i:9+i]
    d=c.count("")
    l8.append(d)
    co=co+1
    print(co,"row null value:",d)
    for i in range(0,len(l8)):
    if l8[i]>m:
    lk+=1
    m=l8[i]
    lk=i+1
    print("repeated mobile mobile no:",b)
    print("max null record rows",lk)

    ردحذف
  7. import json
    j = '[{"a":"1", "b":"2", "c":"3", "d":"4"}]'
    a = json.loads(j)
    for i in range(len(a)):
    for j in a[i]:
    print(j,":",a[i][j])

    ردحذف
  8. import json
    f = open('P:\\excel\\pk.json')
    a = json.load(f)
    for i in a['result']:
    for j in i:
    print(j,":",i[j])

    ردحذف
  9. import csv

    f= open("P:\\word\\covid_19_india.csv")
    c =csv.reader(f)
    c1 = 0
    for row in c:
    print(row)
    c1+=1
    print("line count",c1)

    ردحذف

إرسال تعليق

POST Answer of Questions and ASK to Doubt

المشاركات الشائعة من هذه المدونة

DSA in C# | Data Structure and Algorithm using C#

  DSA in C# |  Data Structure and Algorithm using C#: Lecture 1: Introduction to Data Structures and Algorithms (1 Hour) 1.1 What are Data Structures? Data Structures are ways to store and organize data so it can be used efficiently. Think of data structures as containers that hold data in a specific format. Types of Data Structures: Primitive Data Structures : These are basic structures built into the language. Example: int , float , char , bool in C#. Example : csharp int age = 25;  // 'age' stores an integer value. bool isStudent = true;  // 'isStudent' stores a boolean value. Non-Primitive Data Structures : These are more complex and are built using primitive types. They are divided into: Linear : Arrays, Lists, Queues, Stacks (data is arranged in a sequence). Non-Linear : Trees, Graphs (data is connected in more complex ways). Example : // Array is a simple linear data structure int[] number...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025

 Top 50 Most Asked MERN Stack Interview Questions and Answers for 2025 Now a days most of the IT Company asked NODE JS Question mostly in interview. I am creating this article to provide help to all MERN Stack developer , who is in doubt that which type of question can be asked in MERN Stack  then they can learn from this article. I am Shiva Gautam,  I have 15 Years of experience in Multiple IT Technology, I am Founder of Shiva Concept Solution Best Programming Institute with 100% Job placement guarantee. for more information visit  Shiva Concept Solution 1. What is the MERN Stack? Answer : MERN Stack is a full-stack JavaScript framework using MongoDB (database), Express.js (backend framework), React (frontend library), and Node.js (server runtime). It’s popular for building fast, scalable web apps with one language—JavaScript. 2. What is MongoDB, and why use it in MERN? Answer : MongoDB is a NoSQL database that stores data in flexible, JSON-like documents. It...