示例#1
0
def main(fips, county):

    #county = 'Lubbock'
    #fips = '303'

    figures = []

    #Fulfills the 'Number' Column of the Table
    county_data_2010_number = api.api_request(
        p.frankenstein(p.table_7_call_2010_number, fips))
    county_data_2000_number = api.api_request(
        p.frankenstein(p.table_7_call_2000_number, fips))

    #Fulfills the 'Avg. HH Size' Column of the Table
    county_data_2010 = api.api_request(
        p.frankenstein(p.table_7_call_2010, fips))
    county_data_2000 = api.api_request(
        p.frankenstein(p.table_7_call_2000, fips))

    #All necessary data prior to 2000
    county_data_1990 = get_excel_data(p.table7_excel_1990, county, 1990)
    county_data_1980 = get_excel_data(p.table7_excel_1980, county, 1980)

    county_data_2010 = table7_string_converter(pop.splitter(county_data_2010))
    county_data_2000 = table7_string_converter(pop.splitter(county_data_2000))
    county_data_2010_number = pop.string_converter(
        "county", pop.splitter(county_data_2010_number))
    county_data_2000_number = pop.string_converter(
        "county", pop.splitter(county_data_2000_number))

    table7 = make_table7(county, county_data_2010, county_data_2000,
                         county_data_2010_number, county_data_2000_number,
                         county_data_1990, county_data_1980)
    figures.append(table7)

    figure4 = make_figure4(county, county_data_2010, county_data_2000,
                           county_data_1990, county_data_1980)
    figures.append(figure4)

    plt.close()
    plt.cla()
    """
    #Gets written to Excel
    writer = pd.ExcelWriter('output.xlsx', engine='xlsxwriter')
    workbook = writer.book
    worksheet = workbook.add_worksheet('Table 7')
    writer.sheets['Table 7'] = worksheet
    worksheet.write_string(0, 0, table7.name)
    
    table7.to_excel(writer, sheet_name='Table 7', startrow=1, startcol=0)
    """

    return figures
示例#2
0
def get_nominal(county, base_year, fips):
    #Read file for data prior to 2000
    income_data = pd.read_excel("Historical_Median_Income_TXcounties1969-89.xlsx")    
    income_data = income_data.loc[income_data['Name'] == county]
    
    #Only a figure for the base year is needed.
    #Source of this data is determined by these conditional statements looking
    #For both County Specified and Base Year
    if(base_year == float(2000)):
        if(county == "State of Texas"):
            nominal = api.api_request("https://api.census.gov/data/2000/sf3?get=HCT012001,NAME&for=state:48&key=" + p.census_api_key)
            nominal = pop.string_converter("state", pop.splitter(nominal))
        else:
            nominal = api.api_request(p.frankenstein(p.nominal2000, fips))
            nominal = pop.string_converter("county", pop.splitter(nominal))
        nominal = float(nominal["HCT012001"])
    elif(base_year < float(2000)):
        nominal = income_data[base_year].values[0]
    else:
        if(county == "State of Texas"):
            nominal = api.api_request("https://api.census.gov/data/"+ str(base_year) +"/acs/acs1?get=NAME,B19013_001E&for=state:48&key=" + p.census_api_key)
            nominal = pop.string_converter("state", pop.splitter(nominal))
        else:
            nominal = api.api_request(p.acs_frankenstein(str(base_year), "B19013_001E", fips, "1"))
            if(nominal is None):
                return None
            else:
                nominal = popt.table3_string_converter(pop.splitter(nominal))
        nominal = float(nominal["B19013_001E"])
        
    return nominal
def base_year_data(fips):
    called_data = api_request(p.frankenstein(p.table1_call_2010, fips))
    called_data = pop.string_converter('county', pop.splitter(called_data))
    #print(called_data)
    converted_data = float(called_data['P001001'])

    return converted_data
def main(fips, county):

    figures = []

    data_TDC = pd.read_csv(p.table3_excel, sep=r'\,|\t', engine='python')
    #Make call to API for data
    population_ACS = api_request(p.frankenstein(p.table_3_call, fips))

    data_ACS = table3_string_converter(pop.splitter(population_ACS))

    table3 = make_table3(data_ACS, data_TDC, 2012, fips)
    figures.append(table3)

    plt.close()

    table4 = make_table4(data_TDC, fips, county)
    figures.append(table4)
    """
    print(table3)
    print(table4)
    """

    figure3 = make_figure3(data_TDC, fips, county)
    figures.append(figure3)

    return figures
def make_table5(fips, county):
    group_quarter_data = group_quarters_array(fips)
    column_2 = table_5_other_columns(fips, "2011")
    column_3 = table_5_other_columns(fips, "2012")
    
    data_2010 = api.api_request(p.frankenstein(p.table1_call_2010, fips))
    
    data_2010 = pop.string_converter("county", pop.splitter(data_2010))
    total_population_2010 = float(data_2010["P001001"])
    
    percent_of_population_2010 = "{0:.2%}".format(float(group_quarter_data[0])/total_population_2010)
    
    
    group_quarter_data.append(percent_of_population_2010)
    
    table5 = pd.DataFrame({"2010": group_quarter_data,
                           "2011": column_2,
                           "2012": column_3})
    table5 = table5.rename(index={0: "Total",
                         1: "Correctional Institutions",
                         2: "Juvenile Institutions",
                         3: "Nursing Homes",
                         4: "Other Institutions",
                         5: "Total Institutional",
                         6: "College Dorms",
                         7: "Military Quarters",
                         8: "Other Non-Institutional",
                         9: "Total Non-Institutional",
                         10: "Percent of Total Population"})
    table5.name = "Recent Trends in Group Quarters Population for " + county + " County"
    
    return table5
def group_quarters_array(fips):
    #Make calls to the API
    #2010
    total_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_total, fips))
    correctional_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_correctional, fips))
    juvenile_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_juvenile, fips))
    nursing_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_nursing, fips))
    other_institutional_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_otherinstitutional, fips))
    total_institutional_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_totalinstitutional, fips))
    dorms_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_dorms, fips))
    military_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_military, fips))
    other_noninstitutional_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_othernoninstitutional, fips))
    total_noninstitutional_2010 = api.api_request(p.frankenstein(p.table_5_call_2010_totalnoninstitutional, fips))
    
    #Turn these requests into something readable
    total_2010 = pop.string_converter("county", pop.splitter(total_2010))
    correctional_2010 = pop.string_converter("county", pop.splitter(correctional_2010))
    juvenile_2010 = pop.string_converter("county", pop.splitter(juvenile_2010))
    nursing_2010 = pop.string_converter("county", pop.splitter(nursing_2010))
    other_institutional_2010 = pop.string_converter("county", pop.splitter(other_institutional_2010))
    total_institutional_2010 = pop.string_converter("county", pop.splitter(total_institutional_2010))
    dorms_2010 = pop.string_converter("county", pop.splitter(dorms_2010))
    military_2010 = pop.string_converter("county", pop.splitter(military_2010))
    other_noninstitutional_2010 = pop.string_converter("county", pop.splitter(other_noninstitutional_2010))
    total_noninstitutional_2010 = pop.string_converter("county", pop.splitter(total_noninstitutional_2010))


    #Make an array

    group_quarter_data = [total_2010["P029026"], correctional_2010["PCT020003"],
                          juvenile_2010["PCT020010"], nursing_2010["P042005"],
                          other_institutional_2010["PCT020015"], 
                          total_institutional_2010["P042002"],
                          dorms_2010["P042008"], military_2010["P042009"],
                          other_noninstitutional_2010["PCT020026"],
                          total_noninstitutional_2010["P029028"]]

    return group_quarter_data 
def main(fips):

    figures = []

    #variables containing state data
    state_data_2010 = api_request(p.table1_call_state_2010)
    print("this is the data after api requst: ", type(state_data_2010))
    state_data_2010 = string_converter('state', splitter(state_data_2010))
    state_population_2010 = float(state_data_2010['P001001'])

    state_data_2000 = api_request(p.table1_call_state_2000)
    print("TEST TEST TEST:", state_data_2000)
    state_data_2000 = string_converter('state', splitter(state_data_2000))
    state_population_2000 = float(state_data_2000['P001001'])

    state_population_1970 = find_population("000", 48, 1970, data)
    state_population_1980 = find_population("000", 48, 1980, data)
    state_population_1990 = find_population("000", 48, 1990, data)

    #variables containing census data
    data_2010 = api_request(p.frankenstein(p.table1_call_2010, fips))
    data_2010 = string_converter('county', splitter(data_2010))
    population_2010 = float(data_2010['P001001'])

    data_2000 = api_request(p.frankenstein(p.table1_call_2000, fips))
    data_2000 = string_converter('county', splitter(data_2000))
    population_2000 = float(data_2000['P001001'])

    population_1970 = find_population(data_2010['county'], data_2010['state'],
                                      1970, data)
    population_1980 = find_population(data_2010['county'], data_2010['state'],
                                      1980, data)
    population_1990 = find_population(data_2010['county'], data_2010['state'],
                                      1990, data)

    figure1 = make_figure1(population_1970, population_1980, population_1990,
                           population_2000, population_2010, data_2010)

    figures.append(figure1)

    plt.close()

    table1 = make_table1(state_population_2010, state_population_2000,
                         state_population_1990, state_population_1980,
                         state_population_1970, population_2010,
                         population_2000, population_1990, population_1980,
                         population_1970, data_2010)

    figures.append(table1)

    figure2 = make_figure2(state_population_2010, state_population_2000,
                           state_population_1990, state_population_1980,
                           state_population_1970, population_2010,
                           population_2000, population_1990, population_1980,
                           population_1970, data_2010)

    plt.close()

    figures.append(figure2)

    table2 = make_table2(state_population_2010, state_population_2000,
                         state_population_1990, state_population_1980,
                         state_population_1970, population_2010,
                         population_2000, population_1990, population_1980,
                         population_1970, data_2010)

    figures.append(table2)
    """
    #Prints to Console
    figure1.show()
    print(table1)
    figure2.show()
    print(table2)

    
    #Gets written to Excel
    writer = pd.ExcelWriter('output.xlsx', engine='xlsxwriter')
    workbook = writer.book
    worksheet = workbook.add_worksheet('Results')
    writer.sheets['Results'] = worksheet
    worksheet.write_string(0, 0, table1.name)
    
    table1.to_excel(writer, sheet_name='Results', startrow=1, startcol=0)
    worksheet.write_string(table1.shape[0] + 4, 0, table2.name)
    table2.to_excel(writer,sheet_name='Results', startrow=table1.shape[0]+5, startcol=0)
    #figure1.to_excel('output.xlsx', sheet_name='figures', engine='xlsxwriter')
    writer.save()
    """

    return figures