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()函数接受:

  1. 日期时间格式:(年、月、日):integer
# Import the DateFormatter ModulesfromFederal.FormatterimportDateFormatter#Insatiate the DateFormatter Objectd=DateFormatter()d.start_date(1900,1,1)d.end_date(2018,1,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')
  1. 日期时间格式:(日-月-年):string
# Import the DateFormatter ModulesfromFederal.FormatterimportDateFormatter#Insatiate the DateFormatter Objectd=DateFormatter()d.start_date('1-1-1900')d.end_date('1-1-2018')
  1. 日期时间格式:(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')
  1. 日期时间格式:(月/日/年):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()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java需要设置框架。可设置大小(false)以重新绘制()   java我对PDF文件感到困惑   为什么是太阳。jvm。热点。调试器。DebuggerException:无法打开二进制文件`?   设置结果为textview时出现java空指针异常   我应该使用什么同步原语在Java中实现事件驱动程序框架?   java为什么WindowClosing处理程序在退出程序之前不执行后台任务?   如何将“20170712T18:43:04.000Z”转换为安卓或java中的相对时间?   Java,获取按键的时间长度,currentTimeMillies()始终为24   maven构建的java可执行Jar找不到logback。xml   java在其外部的函数中使用for循环中的值   java如何以表格格式将不同长度的数据对齐   java Play 2.5 WebSocket连接构建   maven而非eclipse的java强制转换问题   java如何在JFreeChart中使X轴上的值水平?   构建Java Windows应用程序以访问在线MySQL数据库需要什么   java添加构造函数会出错吗?这没有道理,请帮忙,编程问题   java在一个jframe中的两个JPanel中使用两个绘制方法   java数学或逻辑问题   java如何复制Androids库存摄像头方向更改