def load_soi_farm_prop(data_tree=naics.generate_tree(), blue_tree=None, blueprint=None, from_out=False, out_path=_FARM_PROP_OUT_PATH): """ This function loads the soi nonfarm proprietorship data: :param data_tree: The NAICS tree to read the data into. :param cols_dict: A dictionary mapping dataframe columns to the name of the column names in the input file :param blueprint: The key corresponding to a dataframe in a tree to be used as a "blueprint" for populating the df_list dataframes forward. :param blue_tree: A NAICS tree with the "blueprint" dataframe. The default is the original NAICS tree. :param from_out: Whether to read in the data from output. :param output_path: The path of the output file. """ # If from_out, load the data tree from output: if from_out: data_tree = naics.load_tree_dfs(input_path=out_path, tree=data_tree) return data_tree # Load Farm Proprietorship data: farm_data = pd.read_csv(_FARM_IN_PATH) new_farm_cols = ["Land", "FA"] # data_tree.append_all(df_nm=_FARM_DF_NM, df_cols=new_farm_cols) # land_mult = ((farm_data["R_sp"][0] + farm_data["Q_sp"][0]) * (float(farm_data["A_sp"][0]) / farm_data["A_p"][0])) total = farm_data["R_p"][0] + farm_data["Q_p"][0] total_pa = 0 cur_codes = [111, 112] proportions = np.zeros(len(cur_codes)) proportions = naics.get_proportions(cur_codes, data_tree, _AST_PRT_DF_NM, [_LAND_COL_NM, _DEPR_COL_NM]) # for ind_code in cur_codes: cur_ind = naics.find_naics(data_tree, ind_code) cur_df = cur_ind.data.dfs[_AST_PRT_DF_NM] total_pa += (cur_df[_LAND_COL_NM][0] + cur_df[_DEPR_COL_NM][0]) # for i in xrange(0, len(cur_codes)): cur_ind = naics.find_naics(data_tree, cur_codes[i]) cur_ind.data.dfs[_FARM_DF_NM]["Land"][0] = ( land_mult * cur_ind.data.dfs[_AST_PRT_DF_NM][_LAND_COL_NM][0] / total_pa) cur_ind.data.dfs[_FARM_DF_NM]["FA"][0] = ( (proportions.iloc[1, i] * total) - cur_ind.data.dfs[_FARM_DF_NM]["Land"][0]) # Default: if blueprint == None and _TOT_CORP_DF_NM in data_tree.enum_inds[ 0].data.dfs.keys(): blueprint = _TOT_CORP_DF_NM naics.pop_back(tree=data_tree, df_list=[_FARM_DF_NM]) naics.pop_forward(tree=data_tree, df_list=[_FARM_DF_NM], blueprint=blueprint, blue_tree=blue_tree) # return data_tree
def load_soi_farm_prop(data_tree = naics.generate_tree(), blue_tree = None, blueprint = None, from_out=False, out_path=_FARM_PROP_OUT_PATH): """ This function loads the soi nonfarm proprietorship data: :param data_tree: The NAICS tree to read the data into. :param cols_dict: A dictionary mapping dataframe columns to the name of the column names in the input file :param blueprint: The key corresponding to a dataframe in a tree to be used as a "blueprint" for populating the df_list dataframes forward. :param blue_tree: A NAICS tree with the "blueprint" dataframe. The default is the original NAICS tree. :param from_out: Whether to read in the data from output. :param output_path: The path of the output file. """ # If from_out, load the data tree from output: if from_out: data_tree = naics.load_tree_dfs(input_path=out_path, tree=data_tree) return data_tree # Load Farm Proprietorship data: farm_data = pd.read_csv(_FARM_IN_PATH) new_farm_cols = ["Land", "FA"] # for i in data_tree.enum_inds: i.append_dfs((_FARM_DF_NM, pd.DataFrame(np.zeros((1,len(new_farm_cols))), columns=new_farm_cols))) # land_mult = ((farm_data["R_sp"][0] + farm_data["Q_sp"][0]) * (float(farm_data["A_sp"][0])/farm_data["A_p"][0])) total = farm_data.iloc[0,0] + farm_data.iloc[0,2] total_pa = 0 cur_codes = [111,112] proportions = np.zeros(len(cur_codes)) proportions = naics.get_proportions(cur_codes, data_tree, "PA_assets", ["Land (Net)","Depreciable assets (Net)"]) # for i in xrange(0, len(cur_codes)): cur_ind = naics.find_naics(data_tree, cur_codes[i]) cur_df = cur_ind.data.dfs["PA_assets"] total_pa += (cur_df["Land (Net)"][0] + cur_df["Depreciable assets (Net)"][0]) # for i in xrange(0,len(cur_codes)): cur_ind = naics.find_naics(data_tree, cur_codes[i]) cur_ind.data.dfs[_FARM_DF_NM]["Land"][0] = (land_mult * cur_ind.data.dfs["PA_assets"]["Land (Net)"][0]/ total_pa) cur_ind.data.dfs[_FARM_DF_NM]["FA"][0] = ((proportions.iloc[1,i]*total) - cur_ind.data.dfs[_FARM_DF_NM]["Land"][0]) # Default: if blueprint == None and _TOT_CORP_DF_NM in data_tree.enum_inds[0].data.dfs.keys(): blueprint = _TOT_CORP_DF_NM naics.pop_back(tree=data_tree, df_list=[_FARM_DF_NM]) naics.pop_forward(tree=data_tree, df_list=[_FARM_DF_NM], blueprint=blueprint, blue_tree=blue_tree) # return data_tree
def load_soi_farm_prop(data_tree = None, blue_tree = None, blueprint = None): # if data_tree == None: data_tree = naics.generate_tree() #Load Farm Proprietorship data: farm_data = pd.read_csv(os.path.abspath(prop_dir + "\\Farm_Data.csv")) new_farm_cols = ["Land", "FA"] # for i in data_tree.enum_inds: i.append_dfs(("farm_prop", pd.DataFrame(np.zeros((1,len(new_farm_cols))), columns=new_farm_cols))) # land_mult = ((farm_data["R_sp"][0] + farm_data["Q_sp"][0]) * (float(farm_data["A_sp"][0])/farm_data["A_p"][0])) total = farm_data.iloc[0,0] + farm_data.iloc[0,2] total_pa = 0 cur_codes = [111,112] proportions = np.zeros(len(cur_codes)) proportions = naics.get_proportions(cur_codes, data_tree, "PA_assets", ["Land (Net)","Depreciable assets (Net)"]) # for i in xrange(0, len(cur_codes)): cur_ind = naics.find_naics(data_tree, cur_codes[i]) cur_df = cur_ind.data.dfs["PA_assets"] total_pa += (cur_df["Land (Net)"][0] + cur_df["Depreciable assets (Net)"][0]) # for i in xrange(0,len(cur_codes)): cur_ind = naics.find_naics(data_tree, cur_codes[i]) cur_ind.data.dfs["farm_prop"]["Land"][0] = (land_mult * cur_ind.data.dfs["PA_assets"]["Land (Net)"][0]/ total_pa) cur_ind.data.dfs["farm_prop"]["FA"][0] = ((proportions.iloc[1,i]*total) - cur_ind.data.dfs["farm_prop"]["Land"][0]) # Default: if blueprint == None and "tot_corps" in data_tree.enum_inds[0].data.dfs.keys(): blueprint = "tot_corps" naics.pop_back(tree=data_tree, df_list=["farm_prop"]) naics.pop_forward(tree=data_tree, df_list=["farm_prop"], blueprint=blueprint, blue_tree=blue_tree) # return data_tree