Jul-31-2020, 10:48 PM
(Jul-31-2020, 05:54 PM)illmattic Wrote: So I would just create a new user variable with name PYTHONPATH and the directory for the value?
Alright, well this did the trick but other problems have arisen.
so in my current working file (F:\Python\Projects\WorkingFile) I write 'from EconomicData.US_data import US_mb'
hoping to get the 'US_mb' variable from F:\Python\Projects\EconomicData but this error pops up:
Error:Traceback (most recent call last):
File "F:/Investments/Python/Projects/GoldData/data.py", line 46, in <module>
from EconomicData.US_data import US_mb
File "F:\Investments\Python\Projects\EconomicData\US_data.py", line 41, in <module>
US_trade = pd.read_excel('US Trade.xlsx',index_col='Date')
File "F:\Investments\Python\Projects\GoldData\venv\lib\site-packages\pandas\util\_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "F:\Investments\Python\Projects\GoldData\venv\lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "F:\Investments\Python\Projects\GoldData\venv\lib\site-packages\pandas\io\excel\_base.py", line 867, in __init__
self._reader = self._engines[engine](self._io)
File "F:\Investments\Python\Projects\GoldData\venv\lib\site-packages\pandas\io\excel\_xlrd.py", line 22, in __init__
super().__init__(filepath_or_buffer)
File "F:\Investments\Python\Projects\GoldData\venv\lib\site-packages\pandas\io\excel\_base.py", line 353, in __init__
self.book = self.load_workbook(filepath_or_buffer)
File "F:\Investments\Python\Projects\GoldData\venv\lib\site-packages\pandas\io\excel\_xlrd.py", line 37, in load_workbook
return open_workbook(filepath_or_buffer)
File "F:\Investments\Python\Projects\GoldData\venv\lib\site-packages\xlrd\__init__.py", line 111, in open_workbook
with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'US Trade.xlsx'
Process finished with exit code 1
It's confusing cause this excel file is related to a different variable but to find a solution I add the 'US Trade.xlsx' file into the current directory and I am able to get the 'US_mb' variable. Can someone tell me why this is and how I can fix it? This is the code from US_data.pyimport pandas as pd from functions import data_extract from functions import combine_data from functions import data_extract_monthlysum pce_inflation = data_extract('FRED/PCEPILFE', 'Core_PCE', 'yes',3) cpi_inflation = data_extract('FRED/CPIAUCNS', 'CPI', 'yes',3) core_cpi = data_extract('FRED/CPILFENS', 'Core_CPI', 'yes', 3) ppi = data_extract('FRED/WPUFD49207', 'PPI', 'yes', 3) core_ppi = data_extract('FRED/WPUFD4131', 'Core_PPI', 'yes', 3) five_year = data_extract('FRED/T5YIFRM', '5yr-5yr_Forward_Inflation_Expectation','no',1) import_inflation = data_extract('FRED/IR', 'Import_Price_Inflation', 'yes', 3) US_inflation = combine_data([pce_inflation,cpi_inflation,core_cpi,ppi,core_ppi,five_year,import_inflation]) US_m2 = data_extract('FRED/M2','M2','yes',0) US_m1 = data_extract('FRED/M1','M1','yes',1) US_mb = data_extract('FRED/BOGMBASEW', 'Monetary_Base','yes',0) US_comm_loans = data_extract('FRED/CILDCBM027NBOG', 'Commercial&Industrial_Loans','yes',1) US_cons_loans = data_extract('FRED/CLSACBW027NBOG', 'Consumer_Loans','yes',1) US_bank_credit = data_extract('FRED/LOANINVNSA', 'Bank_Credit','yes',1) US_total_loans = US_comm_loans['Commercial&Industrial_Loans'] + US_cons_loans['Consumer_Loans'] US_CI_per_total = US_comm_loans['Commercial&Industrial_Loans'] / US_bank_credit['Bank_Credit']*100 US_ms_credit = combine_data([US_mb,US_m1,US_m2,US_comm_loans,US_cons_loans,US_bank_credit]) US_ms_credit['Total_Loans'] = US_total_loans US_ms_credit['Total_Loans_YY'] = US_total_loans.pct_change(12)*100 US_ms_credit['Total_Loans_YY'] = US_ms_credit['Total_Loans_YY'].round(decimals=1) US_ms_credit['CI_Loans_of_Total_Credit'] = US_CI_per_total US_ms_credit['CI_Loans_of_Total_Credit'] = US_ms_credit['CI_Loans_of_Total_Credit'].round(decimals=1) US_ind_prod = data_extract('FRED/INDPRO', 'Industrial_Production_Index', 'yes',3) US_neworders = data_extract('FRED/NEWORDER', 'New_Goods_Orders_NonDefExAir', 'yes',0) US_new_housing_permits = data_extract('FRED/PERMITNSA', 'New_Housing_Permits', 'yes',0) US_trade = pd.read_excel('US Trade.xlsx',index_col='Date') US_industry = combine_data([US_ind_prod,US_neworders,US_new_housing_permits, US_trade]) US_rpincome = data_extract('FRED/RPI', 'Real_Personal_Income', 'yes',0) US_rpi_ex = data_extract('FRED/W875RX1', 'RPC_ex_transfer_payments', 'yes',0) US_real_disincome = data_extract('FRED/DSPIC96', 'Real_Disposable_Income', 'yes',0) US_real_pce = data_extract('FRED/PCEC96', 'Real_Personal_Consumption_Expenditures', 'yes',0) US_savings_rate = data_extract('FRED/PSAVERT','Savings_Rate','no',1) US_retailSales_exfood = data_extract('FRED/RSXFS', 'Retail_Sales_ExFood','yes',0) US_initial_claims = data_extract_monthlysum('FRED/ICNSA','Initial_Claims', 'yes',0) US_continued_claims = data_extract('FRED/CCNSA', 'Continued_Claims', 'yes', 0) US_consumer = (combine_data([US_rpincome,US_rpi_ex,US_real_disincome,US_real_pce,US_savings_rate,US_retailSales_exfood,US_initial_claims,US_continued_claims])) US_total_data = combine_data([US_consumer,US_industry,US_inflation,US_ms_credit])And here are the functions that I use from a different file:
def data_extract(code, column_name, YY, decimals): api_key = open('quandlapikey.txt', 'r').read() data = quandl.get(code, authtoken=api_key, start_date='2000-01-01', collapse='monthly') pd.options.display.float_format = '{:,}'.format data = data.round(decimals=decimals) data.rename(columns={data.columns[0]: column_name}, inplace=True) if YY =='yes': data[column_name + '_YY'] = data[column_name].pct_change(12)*100 data[column_name + '_YY'] = data[column_name + '_YY'].round(decimals=1) return data else: return data def combine_data(df_merged): df_name = reduce(lambda left,right: pd.merge(left,right,on='Date', how='outer'), df_merged).fillna(method='ffill') return(df_name) def add_YY(value,column_name): data = value.pct_change(12) * 100 data = data.round(decimals=1) value[column_name] = data