python访问wrds数据
wrds的Python项目详细描述
wrds py是一个从wrds数据源中提取数据并将其放入pandas的库。 该库允许用户访问wrd中的数据,并使用sql语句提取数据。数据 返回的数据读入pandas数据帧。
安装
Mac OS/Linux
$python setup.py安装
窗口
wrds-py包需要pandas和psycopg2。这些文件的二进制文件可以在这里找到: http://www.lfd.uci.edu/~gohlke/pythonlibs/#psycopg
一旦安装了两个必需的包,就可以运行 $python setup.py安装
有关更多信息,请参阅https://wrds-web.wharton.upenn.edu/wrds/support/上的wrds支持部分。
用法
>>> import wrds >>> db = wrds.Connection() Enter your credentials. Username: <your_username> Password: <your_password> >>> db.list_libraries() ['audit', 'bank', 'block', 'bvd', 'bvdtrial', 'cboe', ...] >>> db.list_tables(library='crsp') ['aco_amda', 'aco_imda', 'aco_indfnta', 'aco_indfntq', ...] >>> db.describe_table(library='crsp', table='stocknames') Approximately 58957 rows in crsp.stocknames. name nullable type 0 permno True DOUBLE PRECISION 1 permco True DOUBLE PRECISION 2 namedt True DATE ...
>>> stocknames = db.get_table(library='crsp', table='stocknames', obs=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
>>> db.close() # Close the connection to the database...
>>> with wrds.Connection() as db: # You can use a context manager ... stocknames = db.get_table(library='crsp', table='stocknames', obs=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