Lesson 1.5 Developing Backend 3rd Party APIs with analysis and cleaning Python, Flask, Pandas


Key Topics:

3rd Party APIs

What are 3rd Party APIs?

Some popular API’s

Example 1 (Python)

Code 1



Example 2 (Javascript)

Covid 19 3rd Party API

fetch('https://api.covid19api.com/summary')
    .then(response => response.json())
    .then(data => {
      const tbody = document.querySelector('#myTable tbody');
      data.Countries.forEach(country => {
        const row = document.createElement('tr');
        row.innerHTML = `
          <td>${country.Country}</td>
          <td>${country.TotalConfirmed}</td>
          <td>${country.TotalDeaths}</td>
        `;
        tbody.appendChild(row);
      });
    })
    .catch(error => console.error(error));
Country Cases Deaths

Analysis and Cleaning using Python, Flask, and Pandas

What is Analysis and Cleaning?

Pandas

Function Purpose
head() Returns the first n rows of a DataFrame
tail() Returns the last n rows of a DataFrame
read_csv() Reads a CSV file into a Pandas DataFrame
dropna() Removes rows with null values
merge() Merges two DataFrames based on a specified column
sort_values() Sorts a DataFrame by a specified column
describe() Generates descriptive statistics of a DataFrame
scatter() Create a scatter plot of DataFrame data

Example 1

pandascode22
pandascode2output

Example 2

Json file:

{
    "Player ID": {
        "0": 101,
        "1": 102,
        "2": 103,
        "3": 104,
        "4": 105,
        "5": 106,
        "6": 107,
        "7": 108,
        "8": 109,
        "9": 110
    },
    "Name": {
        "0": "Lionel Messi",
        "1": "Cristiano Ronaldo",
        "2": "Neymar Jr",
        "3": "Kylian Mbappé",
        "4": "Mohamed Salah",
        "5": "Kevin De Bruyne",
        "6": "Robert Lewandowski",
        "7": "Virgil van Dijk",
        "8": "Sadio Mané",
        "9": "Jan Oblak"
    },
}

Python code:

pandascode




Flask

Example

flaskcode

Hacks

Choose from 1 of 2 of these hacks:

Option 1:

Find a third party api and display it in a table

Option 2:

Take this python table and use a minimum of 3 pandas functions to analyze the data

import pandas as pd
data = {
    'Name': ['Dillon', 'Noor', 'Steven', 'Lucas', 'Harsha', 'Varalu', 'Ryan', 'Emaad'],
    'Age': [24, 31, 42, 27, 29, 26, 90, 15],
    'Gender': ['M', 'M', 'M', 'M', 'F', 'F', 'F', 'F'],
    'Grade': ['A', 'B', 'A', 'D', 'C', 'F', 'B', 'A']
}
df = pd.DataFrame(data)
print(df)