跳转到主要内容

通过Python中的PostgreSQL访问WRDS数据。

项目描述

WRDS-Py来自沃顿研究数据服务

WRDS-Py是Wharton Research Data Services (WRDS) 平台上数据集检查的Python包,并将数据提取到Pandas数据框中。需要WRDS账户。

安装

WRDS-Py软件包需要Python 3.8或更高版本。为确保您拥有受支持的Python版本,请在命令行界面中输入python --version,并检查版本号是否大于3.8。在某些系统中,Python可能以python3的形式安装。如果尚未安装,您可以在此处下载Python

在首次使用WRDS-Py软件包之前,必须先安装它。推荐的方法是使用虚拟环境venv),这样您就可以在Python中使用它。以下示例将安装WRDS-Py软件包(wrds)和IPython,它提供了比Python自带的命令行界面更好的体验。

Linux或MacOS

$ python -m venv --copies --prompt wrds-py wrds-py
$ source wrds-py/bin/activate
(wrds-py) $ python -m pip install -U pip wheel wrds ipython

在此示例中,Python将在您的当前目录中创建一个venv,即./wrds-py,这样当您再次需要使用它时,可以简单地激活它。

$ source wrds-py/bin/activate

Windows

C:\Users\username> python -m venv --copies --prompt wrds-py wrds-py
C:\Users\username> wrds-py\Scripts\activate
(wrds-py) C:\Users\username> python -m pip install -U pip wheel wrds ipython

在此示例中,Python将在目录C:\Users\username\wrds-py中创建一个venv,这样当您再次需要使用它时,可以简单地激活它。

C:\Users\username> wrds-py\Scripts\activate

有关模块安装的详细信息,请参阅PYTHON: From Your Computer (Jupyter/Spyder)

使用Py-WRDS软件包

输入ipython以启动IPython命令行界面。

有关模块使用的详细信息,请参阅Querying WRDS Data using Python

快速教程

In [1]: import wrds
In [2]: db = wrds.Connection()
Enter your credentials.
Username: <your_username>
Password: <your_password>
In [3]: db.list_libraries()
['audit', 'bank', 'block', 'bvd', 'bvdtrial', 'cboe', ...]
In [4]: db.list_tables(library="crsp")
['aco_amda', 'aco_imda', 'aco_indfnta', 'aco_indfntq', ...]
In [5]: db.describe_table(library="crsp", table="stocknames")
Approximately 58957 rows in crsp.stocknames.
       name    nullable              type
0      permno      True  DOUBLE PRECISION
1      namedt      True              DATE
2   nameenddt      True              DATE
...

In [6]: stocknames = db.get_table(library="crsp", table="stocknames", rows=10)
In [7]: stocknames.head()
   permno  permco      namedt   nameenddt     cusip    ncusip ticker  \
0  10000.0  7952.0  1986-01-07  1987-06-11  68391610  68391610  OMFGA
1  10001.0  7953.0  1986-01-09  1993-11-21  36720410  39040610   GFGC
2  10001.0  7953.0  1993-11-22  2008-02-04  36720410  29274A10   EWST
3  10001.0  7953.0  2008-02-05  2009-08-03  36720410  29274A20   EWST
4  10001.0  7953.0  2009-08-04  2009-12-17  36720410  29269V10   EGAS

In [7]: db.close()  # Close the connection to the database.

In [8]: with wrds.Connection() as db:  # You can use a context manager
   ...:     stocknames = db.get_table(library='crsp', table='stocknames', rows=10)
   ...: stocknames.head()
   permno  permco      namedt   nameenddt     cusip    ncusip ticker  \
0  10000.0  7952.0  1986-01-07  1987-06-11  68391610  68391610  OMFGA
1  10001.0  7953.0  1986-01-09  1993-11-21  36720410  39040610   GFGC
2  10001.0  7953.0  1993-11-22  2008-02-04  36720410  29274A10   EWST
3  10001.0  7953.0  2008-02-05  2009-08-03  36720410  29274A20   EWST
4  10001.0  7953.0  2009-08-04  2009-12-17  36720410  29269V10   EGAS

项目详情


下载文件

下载适用于您平台的应用程序。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源代码发行版

wrds-3.2.0.tar.gz (17.8 kB 查看哈希值

上传时间 源代码

构建发行版

wrds-3.2.0-py3-none-any.whl (13.2 kB 查看哈希值

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面