コード例 #1
0
def get_county_data():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'seven_day_county.csv')
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)
    df['date'] = pd.to_datetime(df['date'])
    return df
コード例 #2
0
def get_territory_list(territory_key='country'):
    """
    Searches .csv file and returns unique regions from region column. Creates
    list of tuples, where the first field is the name of the web page, and the
    second is the page's url.
    :param territory_key: str determining which .csv file to search and filter
    :return: alphabetically sorted list of tuples
    """
    if territory_key == 'country':
        csv_file_name = 'world'
    elif territory_key == 'state':
        csv_file_name = 'states'
    else:
        csv_file_name = 'seven_day_county'
    csv_file_name += '.csv'

    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                csv_file_name)
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)

    if territory_key == 'country':
        territory_list = df.country.unique()
        territory_list = [w.replace('_', ' ') for w in territory_list]

    elif territory_key == 'state':
        territory_list = df.state.unique()

    else:
        territory_list = df.state.unique()

    territory_list = sorted(territory_list)
    return territory_list
コード例 #3
0
ファイル: by_state.py プロジェクト: xyz9911/covid19
def get_state_pop():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)), 'states_population.csv')
    d = {}
    with open(path, 'r') as read_obj:
        reader = csv.DictReader(read_obj)
        for row in reader:
            d[row['state']] = int(row['population_2019'])
    return d
コード例 #4
0
def get_site_last_updated():
    """
    get last updated time stamp
    """
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'site_last_updated.csv')
    with open(path, 'r') as read_obj:
        lines = read_obj.readlines()
    d = datetime.datetime.strptime(
        lines[1][0:19], '%Y-%m-%d %H:%M:%S').strftime("%Y-%m-%d %H:%M:%S")
    return d
コード例 #5
0
ファイル: make_territories.py プロジェクト: xyz9911/covid19
def get_world_data_week():
    """
    get the data from BQ, grouped by week
    """
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'world_week.csv')
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)
    df['country'] = df['country'].str.replace('_', ' ')
    df['date'] = pd.to_datetime(df['date'])
    df['dates'] = df['date']
    return df
コード例 #6
0
def get_totals():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'states_totals.csv')
    d = {}
    with open(path, 'r') as read_obj:
        reader = csv.DictReader(read_obj)
        for row in reader:
            d[row['state']] = {
                'deaths': int(row['deaths']),
                'cases': int(row['cases'])
            }
    return d
コード例 #7
0
ファイル: make_territories.py プロジェクト: xyz9911/covid19
def get_world_data_day():
    """
    Get the data by day for world

    return: df
    """
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)),
                                'world.csv')
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)
    df['country'] = df['country'].str.replace('_', ' ')
    df['date'] = pd.to_datetime(df['date'])
    df['dates'] = df['date']
    return df
コード例 #8
0
ファイル: by_state.py プロジェクト: xyz9911/covid19
def get_data_deaths():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)), 'states_deaths_ranked.csv')
    with open(path, 'r') as read_obj:
        df = pd.read_csv(read_obj)
    df['date'] = pd.to_datetime(df['date'])
    return df
コード例 #9
0
ファイル: state_comparisons.py プロジェクト: xyz9911/covid19
def _get_pop_df():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)), 'states_population.csv')
    df = pd.read_csv(path)
    return df
コード例 #10
0
ファイル: state_comparisons.py プロジェクト: xyz9911/covid19
def _get_state_df():
    path = common.get_data_path(os.path.abspath(os.path.dirname(__file__)), 'states.csv')
    df = pd.read_csv(path)
    df['date'] = pd.to_datetime(df['date'])
    return df