Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New data #217

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ install:
- export BTAX_OUT_DIR=btax_output_dir # make an output dir
- export BTAX_CUR_DIR=${BUILD_DIR}/btax
- mkdir btax_output_dir
- python setup.py develop
- pip install -e .


script:
- python -c "from btax import *" && echo B-Tax can be imported
Expand Down
Binary file modified btax/data/raw_data/BEA/detailnonres_stk1.xlsx
Binary file not shown.
Binary file added btax/data/raw_data/soi/soi_partner/15pa01.xlsx
Binary file not shown.
Binary file added btax/data/raw_data/soi/soi_partner/15pa03.xlsx
Binary file not shown.
Binary file added btax/data/raw_data/soi/soi_partner/15pa05.xlsx
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 5 additions & 3 deletions btax/pull_soi_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def load_partner_data(entity_dfs):
xwalk = xwalk[xwalk['complete'] == 1]
# read in partner data - partner assets
df = format_excel(pd.read_excel(_AST_FILE, skiprows=2,
skip_footer=6))
skipfooter=6))
# Cuts off the repeated columns so only the data for all
# partnerships remains
df.index = [to_str(x) for x in df.index]
Expand All @@ -87,6 +87,7 @@ def load_partner_data(entity_dfs):
df03.reset_index(inplace=True, drop=True)
# Keep only variables of interest
df03.columns = [to_str(c) for c in df03.columns]
df03.to_csv("partner03.csv")
try:
df03['Fixed Assets'] =\
(df03['Depreciable assets'] -
Expand All @@ -101,7 +102,7 @@ def load_partner_data(entity_dfs):

# partner data - income
df01 = format_excel(pd.read_excel(_INC_FILE, skiprows=2,
skip_footer=6))
skipfooter=6))
# Cuts off the repeated columns so only the data for all
# partnerships remains
df01 = df01.T.groupby(sort=False, level=0).first().T
Expand Down Expand Up @@ -213,7 +214,7 @@ def load_partner_data(entity_dfs):
'''

# Read in data by partner type (gives income allocation by partner type)
df05 = format_excel(pd.read_excel(_TYP_FILE, skiprows=1, skip_footer=5))
df05 = format_excel(pd.read_excel(_TYP_FILE, skiprows=1, skipfooter=5))
df05.columns = [to_str(c) for c in df05.columns]
df05 = df05[['Item', 'All partners', 'Corporate general partners',
'Corporate limited partners',
Expand Down Expand Up @@ -370,6 +371,7 @@ def format_excel(df):
df = df.drop(df.index[[0, len(df)-1]])
df = df.fillna(0)
df = df.replace('[d]', 0)
df = df.replace('[d] ', 0)
df = df.replace('[2] ', 0)
df.reset_index(inplace=True, drop=True)
df.iloc[:, 1:] = df.iloc[:, 1:] * _AST_FILE_FCTR
Expand Down
16 changes: 8 additions & 8 deletions btax/read_bea.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def fixed_assets(soi_data):
"""
# Read in BEA fixed asset table
bea_FA = pd.read_excel(_BEA_ASSET_PATH, sheetname="Datasets")
bea_FA = bea_FA[['2013']]
bea_FA = bea_FA[['2014']]
bea_FA['long_code'] = bea_FA.index
bea_FA.dropna(subset=['long_code'], inplace=True)
bea_FA.reset_index(drop=True, inplace=True)
bea_FA.rename(columns={"2013": "assets"}, inplace=True)
bea_FA.rename(columns={"2014": "assets"}, inplace=True)
bea_FA['assets'] = bea_FA['assets'] * _BEA_IN_FILE_FCTR
bea_FA['bea_asset_code'] = bea_FA.long_code.str[-6:-2]
bea_FA['bea_ind_code'] = bea_FA.long_code.str[3:7]
Expand Down Expand Up @@ -136,9 +136,9 @@ def inventories(soi_data):
bea_inventories = pd.read_excel(_BEA_INV, sheetname="Sheet0",
skiprows=6, skip_footer=4)
bea_inventories.reset_index()
bea_inventories = bea_inventories[['Unnamed: 1', 'IV.1']].copy()
bea_inventories = bea_inventories[['Unnamed: 1', 'IV.2']].copy()
bea_inventories.rename(columns={"Unnamed: 1": "bea_inv_name",
"IV.1": "BEA Inventories"},
"IV.2": "BEA Inventories"},
inplace=True)
bea_inventories['bea_inv_name'] =\
bea_inventories['bea_inv_name'].str.strip()
Expand Down Expand Up @@ -187,9 +187,9 @@ def land(soi_data, bea_FA):
bea_residential = pd.read_excel(_BEA_RES, sheetname="Sheet0",
skiprows=5, skip_footer=2)
bea_residential.reset_index()
bea_residential = bea_residential[[u'\xa0', '2013']].copy()
bea_residential = bea_residential[[u'\xa0', '2014']].copy()
bea_residential.rename(columns={u"\xa0": "entity_type",
"2013": "Fixed Assets"},
"2014": "Fixed Assets"},
inplace=True)
bea_residential['Fixed Assets'] *= _BEA_INV_RES_FCTR
bea_residential['entity_type'] = bea_residential['entity_type'].str.strip()
Expand All @@ -208,8 +208,8 @@ def land(soi_data, bea_FA):
# owner occ sector (includes land and structures)
b101 = pd.read_csv(_B101_PATH, header=5, encoding='utf-8')
b101.reset_index()
b101 = b101[['Unnamed: 0', '2013']].copy()
b101.rename(columns={"Unnamed: 0": "Variable", "2013": "Value"},
b101 = b101[['Unnamed: 0', '2014']].copy()
b101.rename(columns={"Unnamed: 0": "Variable", "2014": "Value"},
inplace=True)
b101['Value'] *= _FIN_ACCT_FILE_FCTR
b101['Variable'] = b101['Variable'].str.strip()
Expand Down
10 changes: 5 additions & 5 deletions btax/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ def get_paths():
paths['_PRT_DIR'] = _PRT_DIR = os.path.join(_SOI_DIR, 'soi_partner')
paths['_DETAIL_PART_CROSS_PATH'] = _DETAIL_PART_CROSS_PATH =\
os.path.join(_PRT_DIR, 'partner_crosswalk_detailed_industries.csv')
paths['_INC_FILE'] = _INC_FILE = os.path.join(_PRT_DIR, '13pa01.xls')
paths['_AST_FILE'] = _AST_FILE = os.path.join(_PRT_DIR, '13pa03.xls')
paths['_INC_FILE'] = _INC_FILE = os.path.join(_PRT_DIR, '14pa01.xls')
paths['_AST_FILE'] = _AST_FILE = os.path.join(_PRT_DIR, '14pa03.xls')
paths['_TYP_IN_CROSS_PATH'] = _TYP_IN_CROSS_PATH =\
os.path.join(_PRT_DIR, '13pa05_Crosswalk.csv')
paths['_TYP_FILE'] = _TYP_FILE = os.path.join(_PRT_DIR, '13pa05.xls')
paths['_TYP_FILE'] = _TYP_FILE = os.path.join(_PRT_DIR, '14pa05.xls')
paths['_PROP_DIR'] = _PROP_DIR = os.path.join(_SOI_DIR,
'soi_proprietorship')
paths['_PRT_DIR'] = _PRT_DIR = os.path.join(_SOI_DIR, 'soi_partner')
paths['_NFARM_PATH'] = _NFARM_PATH = os.path.join(_PROP_DIR,
'13sp01br.xls')
'14sp01br.xls')
paths['_NFARM_INV'] = _NFARM_INV = os.path.join(_PROP_DIR,
'13sp02is.xls')
'14sp02is.xls')
paths['_FARM_IN_PATH'] = _FARM_IN_PATH = os.path.join(_PROP_DIR,
'farm_data.csv')
paths['_DETAIL_SOLE_PROP_CROSS_PATH'] =\
Expand Down