Python and Pandas to look for data in the web

Some data searchings made with Python and Pandas, a practical case, to look for data in a particular row, based on a value searched in a column and then getting another value, in another column of that row, like when you need to know for a city a particular number referring to something that you are looking for, like number of inhabitats of the city, in a list of cities, etc.

Below, you can find code and live coding video about this topic: serching data on the web.

import pandas as pd
import requests

def days(day, month, year, pr):
    where = "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-province/dpc-covid19-ita-province-{}{}{}.csv".format(year, month, day)
    url = requests.get(where)
    with open("data2.csv", "w", encoding="utf-8") as file:
        file.write(url.text)
    df = pd.read_csv("data2.csv", error_bad_lines=False)
    mydata = df.loc[df["denominazione_provincia"]==pr]["totale_casi"]
    mytime = df.loc[df["denominazione_provincia"]==pr]["data"]
    print(list(mytime)[0].split()[0], end="\t")
    print(list(mydata)[0])


def province(pr):
    for n in range(1, 15):
        if n < 10:
            days("0" + str(n), "03", "2020", pr)
        else:
            days(str(n), "03", "2020", pr)


province("Milano")


Subscribe to the newsletter for updates
Tkinter templates
My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts