Exemplo n.º 1
0
import pandas as pd
import c19us
import c19all
import dump_csv_and_json

# Check public functions
c19all.for_country(c19all.df_all['cases'], 'France')
c19all.for_province_state(c19all.df_all['cases'], 'British Columbia')

print('Tests passed')
Exemplo n.º 2
0
import pandas as pd
from pprint import pprint as pp
import c19all
import c19us

# c19all.py
print("\nGlobal cases (head):")
pp(c19all.df_all['cases'].head())
print("\nGlobal deaths (head):")
pp(c19all.df_all['deaths'].head())
print("\nGlobal recovered (head):")
pp(c19all.df_all['recovered'].head())
print("\nCases for one country (head):")
pp(c19all.for_country(c19all.df_all['cases'], 'France').head())
print("\nCases for one province_state (head):")
pp(
    c19all.for_province_state(c19all.df_all['cases'],
                              'British Columbia').head())

# c19us.py
# National
print("\nUS Cases (head):")
pp(c19us.df_us_state['cases'].head())
print("\nUS Deaths (head):")
pp(c19us.df_us_state['deaths'].head())
print("\nUS Recovered (head):")
pp(c19us.df_us_state['recovered'].head())
# State
print("\nUS Cases by state (head):")
pp(c19us.df_us_state['cases'].head())
print("\nUS Deaths by state (head):")
Exemplo n.º 3
0
# `us_data_state(df)` Filter input US dataframe state-level records


def _us_data(df):
    df = df.rename(columns={'province_state': 'state_county'})
    df = df[~df.state_county.isin(cruise_ships)]
    # For consistency with census data
    df.state_county = df.state_county.apply(lambda state: (
        state, 'District of Columbia')[state == 'Washington, D.C.'])
    df = df.drop(['country'], axis=1)
    return df


# Dict of all US data.
df_us = {
    'cases': _us_data(c19all.for_country(c19all.df_cases, 'US')),
    'deaths': _us_data(c19all.for_country(c19all.df_deaths, 'US')),
    'recovered': _us_data(c19all.for_country(c19all.df_recovered, 'US'))
}
print("\ndf_us:")
print(df_us['cases'])


def _us_data_state(df):
    df = df.rename(columns={'state_county': 'state'})
    df = df[df.state.isin(us_population.keys())]
    df['population'] = df.state.apply(
        lambda state: us_population[state]['population'])
    df['sub_region'] = df.state.apply(
        lambda state: us_population[state]['sub_region'])
    df['region'] = df.state.apply(lambda state: us_population[state]['region'])
Exemplo n.º 4
0
    df['is_state'] = None
    df['region'] = None
    df['sub_region'] = None
    df['population'] = None
    df = df.apply(lambda row: _parse_location(row), axis=1)
    df = _handle_special_cases(df)
    df = df.reset_index(drop=True)
    df.set_index([
        'date', 'day', 'state', 'county', 'territory', 'other', 'unknown_type',
        'sub_region', 'region', 'is_state'
    ])
    return df.filter(items=_output_columns)


df_us = {
    'cases': _us_data(c19all.for_country(c19all.df_all['cases'], 'US')),
    'deaths': _us_data(c19all.for_country(c19all.df_all['deaths'], 'US')),
    'recovered': _us_data(c19all.for_country(c19all.df_all['recovered'], 'US'))
}


def _by_region_and_state(df):
    df = df[['date', 'region', 'sub_region', 'state', 'population', 'cases']]
    return df.groupby(['date', 'region', 'sub_region', 'state'],
                      as_index=False).sum()


df_us_region_and_state = {
    'cases': _by_region_and_state(df_us['cases']),
    'deaths': _by_region_and_state(df_us['deaths']),
    'recovered': _by_region_and_state(df_us['recovered']),