Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.9 kB
5
Indexable
Never
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import getopt
from datetime import datetime

import pandas as pd

if __name__ == "__main__":

    # Задаём определения входных параметров
    unixOptions = "r:s:e" # напишите код
    gnuOptions = ["regions=", "start_dt=", "end_dt="] # напишите код

    fullCmdArguments = sys.argv
    argumentList = fullCmdArguments[1:]
    try:  
        arguments, values = getopt.getopt(argumentList, unixOptions, gnuOptions)
    except getopt.error as err:  
        print(str(err))
        sys.exit(2)

    # Обрабатываем входные параметры
    regions = 'Germany,France,Russia'.split(',')
    start_dt = '1998-01-01 00:00:00'
    end_dt = '1999-12-31 23:59:59'     
    for currentArgument, currentValue in arguments:  
        if currentArgument in ("-r", "--regions"):
            regions = currentValue.split(',')
        elif currentArgument in ("-s", "--start_dt"):
            start_dt = datetime.strptime(currentValue, format='%Y-%m-%d %H:%M:%S') # напишите код
        elif currentArgument in ("-e", "--end_dt"):
            end_dt = datetime.strptime(currentValue, format='%Y-%m-%d %H:%M:%S') # напишите код

    urbanization = pd.read_csv('/datasets/urbanization.csv')[['Entity', 'Year', 'Urban']]

    # Приводим колонки urbanization к нужным типам
    urbanization['Year'] = pd.to_datetime(urbanization['Year'], format='%Y-%m-%d') # ваш код

    # Фильтруем и определяем максимальный уровень урбанизации
    urbanization = urbanization.query('Entity in @regions and Year >= @start_dt and Year <= @end_dt') # напишите код

    print(urbanization.sort_values(by = ['Entity', 'Year'])) # ваш код