pandas数据读取器包上的一个包装器,用于更方便地处理美联储(federal reserve,fred)的数据
Federal的Python项目详细描述
联邦套餐
这是一个简单的模块,建立在熊猫数据读取器的基础上,使它更容易从圣路易斯联邦储备局(fred)获取联邦储备数据。
安装
pip install Federal
基本用法:
# Import the GDP and DateFormatter ModulesfromFederal.EconimportGDPfromFederal.FormatterimportDateFormatter#Insatiate the GDP and DateFormatter Objectsg=GDP()d=DateFormatter()#Set your Start & End Datesd.start_date(1900,1,1)d.end_date(2018,1,1)# Make the Calldf=g.metro_gdp(name='Houston')df.head()
设置开始和结束日期
导入后,通过DateFormatter.start_date()
和DateFormatter.end_date()
函数声明开始日期和结束日期。这些函数定义您要处理的数据的日期范围。一旦声明,除非显式更改,否则这些值将应用于每个查询。
有几个不同的日期时间格式变体,DateFormatter.start_date()
和DateFormatter.end_date()
函数接受:
- 日期时间格式:(年、月、日):integer
# Import the DateFormatter ModulesfromFederal.FormatterimportDateFormatter#Insatiate the DateFormatter Objectd=DateFormatter()d.start_date(1900,1,1)d.end_date(2018,1,1)
- 日期时间格式:(日/月/年):string
# Import the DateFormatter ModulesfromFederal.FormatterimportDateFormatter#Insatiate the DateFormatter Objectd=DateFormatter()d.start_date('1/1/1900')d.end_date('1/1/2018')
- 日期时间格式:(日-月-年):string
# Import the DateFormatter ModulesfromFederal.FormatterimportDateFormatter#Insatiate the DateFormatter Objectd=DateFormatter()d.start_date('1-1-1900')d.end_date('1-1-2018')
- 日期时间格式:(day.month.year):string
# Import the DateFormatter ModulesfromFederal.FormatterimportDateFormatter#Insatiate the DateFormatter Objectd=DateFormatter()d.start_date('1.1.1900')d.end_date('1.1.2018')
- 日期时间格式:(月/日/年):string
# Import the DateFormatter ModulesfromFederal.FormatterimportDateFormatter#Insatiate the DateFormatter Objectd=DateFormatter()d.start_date('14/1/1900')d.end_date('16/1/2018')
国内生产总值
在实例化一个fred对象并使用GDP.start_date()
和GDP.end_date()
函数定义开始和结束日期之后,您可以根据函数的参数使用函数GDP.national_gdp()
来返回名义gdp或实际gdp。
# Import the GDP and DateFormatter ModulesfromFederal.EconimportGDPfromFederal.FormatterimportDateFormatter#Insatiate the GDP and DateFormatter Objectsg=GDP()d=DateFormatter()#Set Datesd.start_date('1/1/1900')d.end_date('1/1/2018')# Real GDPdf=g.national_gdp()df.head()# Nominal GDPdf=g.national_gdp(nominal=True)df.head()
州国内生产总值(GSP)
与进行必要调用后的GDP.national_gdp()
类似,您可以使用GDP.state_gdp()
函数拉入有关州一级gdp的信息。它需要一个参数,即表示感兴趣状态的两个字符串。在下面的例子中,我们把印第安纳州的GDP拉过来。
# Import the GDP and DateFormatter ModulesfromFederal.EconimportGDPfromFederal.FormatterimportDateFormatter#Insatiate the GDP and DateFormatter Objectsg=GDP()d=DateFormatter()#Set the Datesd.start_date('1/1/1900')d.end_date('1/1/2018')# State GDPdf=g.state_gdp('IN')df.head()
大都市国内生产总值(gmp)
fred模块引入的gdp的最终变化是大都市级gdp。美联储(federal reserve)使用基于核心的统计区域(cbsa)代码在其api中定义每个metro。在这里,使用GDP.metro_gdp()
函数,您可以在函数中传递cbsa代码或metro区域的名称作为参数。除此之外,类似于国家gdp,通过将GDP.metro_gdp(name='<Any Metro Name>',nominal=True)
的名义值设为真,函数将返回名义的地铁gdp。
# Import the GDP and DateFormatter ModulesfromFederal.EconimportGDPfromFederal.FormatterimportDateFormatter#Insatiate the GDP and DateFormatter Objectsg=GDP()d=DateFormatter()#Set the Datesd.start_date('1/1/1900')d.end_date('1/1/2018')# Metropolitan GDP - Passing the City Name as an argumentdf=g.metro_gdp(name='Houston')df.head()# Metropolitan GDP - Passing the CBSA code as an argumentdf=g.metro_gdp(cbsa=26420)df.head()# Metropolitan GDP - nominaldf=g.metro_gdp(cbsa=26420,nominal=True)df.head()# Metropolitan GDP - nominaldf=g.metro_gdp(name='Houston',nominal=True)df.head()
全国失业率
失业是由Unemployment.national_unemp()
函数定义的。此函数接受参数sa
,该参数返回季节性调整的非季节性调整失业率。
# Import the GDP and DateFormatter ModulesfromFederal.EconimportUnemploymentfromFederal.FormatterimportDateFormatter#Insatiate the GDP and DateFormatter Objectsu=Unemployment()d=DateFormatter()#Set the Datesd.start_date('1/1/1900')d.end_date('1/1/2018')# Seasonally-Adjusted National Unemploymentdf=u.national_unemp(sa=True)df.head()# Non Seasonally-Adjusted National Unemploymentdf=u.national_unemp(sa=False)df.head()