Skip to content

Commit 5e3e8d2

Browse files
DOC: convert pandas docs to pandas-datareader + remove google analytics part
1 parent 3c9a450 commit 5e3e8d2

File tree

1 file changed

+32
-99
lines changed

1 file changed

+32
-99
lines changed

docs/source/remote_data.rst

Lines changed: 32 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,48 @@
11
.. _remote_data:
22

3-
.. currentmodule:: pandas
3+
.. currentmodule:: pandas_datareader
44

55
.. ipython:: python
66
:suppress:
77
8-
import os
9-
import csv
108
import pandas as pd
119
1210
import numpy as np
13-
np.random.seed(123456)
14-
randn = np.random.randn
1511
np.set_printoptions(precision=4, suppress=True)
1612
17-
import matplotlib.pyplot as plt
18-
plt.close('all')
13+
pd.options.display.max_rows=15
1914
20-
from pandas import *
21-
options.display.max_rows=15
22-
import pandas.util.testing as tm
2315
2416
******************
2517
Remote Data Access
2618
******************
2719

2820
.. _remote_data.data_reader:
2921

30-
Functions from :mod:`pandas.io.data` and :mod:`pandas.io.ga` extract data from various Internet sources into a DataFrame. Currently the following sources are supported:
22+
Functions from :mod:`pandas_datareader.data` and :mod:`pandas_datareader.wb`
23+
extract data from various Internet sources into a pandas DataFrame.
24+
Currently the following sources are supported:
3125

3226
- :ref:`Yahoo! Finance<remote_data.yahoo>`
3327
- :ref:`Google Finance<remote_data.google>`
3428
- :ref:`St.Louis FED (FRED)<remote_data.fred>`
3529
- :ref:`Kenneth French's data library<remote_data.ff>`
3630
- :ref:`World Bank<remote_data.wb>`
37-
- :ref:`Google Analytics<remote_data.ga>`
3831

3932
It should be noted, that various sources support different kinds of data, so not all sources implement the same methods and the data elements returned might also differ.
4033

4134
.. _remote_data.yahoo:
4235

4336
Yahoo! Finance
44-
--------------
37+
==============
4538

4639
.. ipython:: python
4740
48-
import pandas.io.data as web
41+
import pandas_datareader.data as web
4942
import datetime
5043
start = datetime.datetime(2010, 1, 1)
5144
end = datetime.datetime(2013, 1, 27)
52-
f=web.DataReader("F", 'yahoo', start, end)
45+
f = web.DataReader("F", 'yahoo', start, end)
5346
f.ix['2010-01-04']
5447
5548
.. _remote_data.yahoo_options:
@@ -66,7 +59,7 @@ to the specific option you want.
6659

6760
.. ipython:: python
6861
69-
from pandas.io.data import Options
62+
from pandas_datareader.data import Options
7063
aapl = Options('aapl', 'yahoo')
7164
data = aapl.get_all_data()
7265
data.iloc[0:5, 0:5]
@@ -113,69 +106,71 @@ The ``month`` and ``year`` parameters can be used to get all options data for a
113106
.. _remote_data.google:
114107

115108
Google Finance
116-
--------------
109+
==============
117110

118111
.. ipython:: python
119112
120-
import pandas.io.data as web
113+
import pandas_datareader.data as web
121114
import datetime
122115
start = datetime.datetime(2010, 1, 1)
123116
end = datetime.datetime(2013, 1, 27)
124-
f=web.DataReader("F", 'google', start, end)
117+
f = web.DataReader("F", 'google', start, end)
125118
f.ix['2010-01-04']
126119
127120
.. _remote_data.fred:
128121

129122
FRED
130-
----
123+
====
131124

132125
.. ipython:: python
133126
134-
import pandas.io.data as web
127+
import pandas_datareader.data as web
135128
import datetime
136129
start = datetime.datetime(2010, 1, 1)
137130
end = datetime.datetime(2013, 1, 27)
138-
gdp=web.DataReader("GDP", "fred", start, end)
131+
gdp = web.DataReader("GDP", "fred", start, end)
139132
gdp.ix['2013-01-01']
140133
141134
# Multiple series:
142135
inflation = web.DataReader(["CPIAUCSL", "CPILFESL"], "fred", start, end)
143136
inflation.head()
137+
138+
144139
.. _remote_data.ff:
145140

146141
Fama/French
147-
-----------
142+
===========
148143

149144
Dataset names are listed at `Fama/French Data Library
150145
<http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html>`__.
151146

152147
.. ipython:: python
153148
154-
import pandas.io.data as web
155-
ip=web.DataReader("5_Industry_Portfolios", "famafrench")
149+
import pandas_datareader.data as web
150+
ip = web.DataReader("5_Industry_Portfolios", "famafrench")
156151
ip[4].ix[192607]
157152
158153
.. _remote_data.wb:
159154

160155
World Bank
161-
----------
156+
==========
162157

163158
``pandas`` users can easily access thousands of panel data series from the
164159
`World Bank's World Development Indicators <http://data.worldbank.org>`__
165160
by using the ``wb`` I/O functions.
166161

167162
Indicators
168-
~~~~~~~~~~
163+
----------
169164

170165
Either from exploring the World Bank site, or using the search function included,
171-
every world bank indicator is accessible.
166+
every world bank indicator is accessible.
172167

173168
For example, if you wanted to compare the Gross Domestic Products per capita in
174169
constant dollars in North America, you would use the ``search`` function:
175170

176171
.. code-block:: python
177172
178-
In [1]: from pandas.io import wb
173+
In [1]: from pandas_datareader import wb
179174
180175
In [2]: wb.search('gdp.*capita.*const').iloc[:,:2]
181176
Out[2]:
@@ -283,25 +278,23 @@ populations in rich countries tend to use cellphones at a higher rate:
283278
==============================================================================
284279
285280
Country Codes
286-
~~~~~~~~~~~~~
287-
288-
.. versionadded:: 0.15.1
281+
-------------
289282
290-
The ``country`` argument accepts a string or list of mixed
283+
The ``country`` argument accepts a string or list of mixed
291284
`two <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2>`__ or `three <http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3>`__ character
292285
ISO country codes, as well as dynamic `World Bank exceptions <http://data.worldbank.org/node/18>`__ to the ISO standards.
293286
294-
For a list of the the hard-coded country codes (used solely for error handling logic) see ``pandas.io.wb.country_codes``.
287+
For a list of the the hard-coded country codes (used solely for error handling logic) see ``pandas_datareader.wb.country_codes``.
295288
296289
Problematic Country Codes & Indicators
297-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290+
--------------------------------------
298291
299292
.. note::
300293
301-
The World Bank's country list and indicators are dynamic. As of 0.15.1,
294+
The World Bank's country list and indicators are dynamic. As of 0.15.1,
302295
:func:`wb.download()` is more flexible. To achieve this, the warning
303296
and exception logic changed.
304-
297+
305298
The world bank converts some country codes,
306299
in their response, which makes error checking by pandas difficult.
307300
Retired indicators still persist in the search.
@@ -321,71 +314,11 @@ There are at least 4 kinds of country codes:
321314
There are at least 3 kinds of indicators:
322315
323316
1. Current - Returns data.
324-
2. Retired - Appears in search results, yet won't return data.
317+
2. Retired - Appears in search results, yet won't return data.
325318
3. Bad - Will not return data.
326319
327320
Use the ``errors`` argument to control warnings and exceptions. Setting
328321
errors to ignore or warn, won't stop failed responses. (ie, 100% bad
329-
indicators, or a single "bad" (#4 above) country code).
322+
indicators, or a single "bad" (#4 above) country code).
330323
331324
See docstrings for more info.
332-
333-
.. _remote_data.ga:
334-
335-
Google Analytics
336-
----------------
337-
338-
The :mod:`~pandas.io.ga` module provides a wrapper for
339-
`Google Analytics API <https://developers.google.com/analytics/devguides>`__
340-
to simplify retrieving traffic data.
341-
Result sets are parsed into a pandas DataFrame with a shape and data types
342-
derived from the source table.
343-
344-
Configuring Access to Google Analytics
345-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
346-
347-
The first thing you need to do is to setup accesses to Google Analytics API. Follow the steps below:
348-
349-
#. In the `Google Developers Console <https://console.developers.google.com>`__
350-
#. enable the Analytics API
351-
#. create a new project
352-
#. create a new Client ID for an "Installed Application" (in the "APIs & auth / Credentials section" of the newly created project)
353-
#. download it (JSON file)
354-
#. On your machine
355-
#. rename it to ``client_secrets.json``
356-
#. move it to the ``pandas/io`` module directory
357-
358-
The first time you use the :func:`read_ga` funtion, a browser window will open to ask you to authentify to the Google API. Do proceed.
359-
360-
Using the Google Analytics API
361-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
362-
363-
The following will fetch users and pageviews (metrics) data per day of the week, for the first semester of 2014, from a particular property.
364-
365-
.. code-block:: python
366-
367-
import pandas.io.ga as ga
368-
ga.read_ga(
369-
account_id = "2360420",
370-
profile_id = "19462946",
371-
property_id = "UA-2360420-5",
372-
metrics = ['users', 'pageviews'],
373-
dimensions = ['dayOfWeek'],
374-
start_date = "2014-01-01",
375-
end_date = "2014-08-01",
376-
index_col = 0,
377-
filters = "pagePath=~aboutus;ga:country==France",
378-
)
379-
380-
The only mandatory arguments are ``metrics,`` ``dimensions`` and ``start_date``. We can only strongly recommend you to always specify the ``account_id``, ``profile_id`` and ``property_id`` to avoid accessing the wrong data bucket in Google Analytics.
381-
382-
The ``index_col`` argument indicates which dimension(s) has to be taken as index.
383-
384-
The ``filters`` argument indicates the filtering to apply to the query. In the above example, the page has URL has to contain ``aboutus`` AND the visitors country has to be France.
385-
386-
Detailed informations in the followings:
387-
388-
* `pandas & google analytics, by yhat <http://blog.yhathq.com/posts/pandas-google-analytics.html>`__
389-
* `Google Analytics integration in pandas, by Chang She <http://quantabee.wordpress.com/2012/12/17/google-analytics-pandas/>`__
390-
* `Google Analytics Dimensions and Metrics Reference <https://developers.google.com/analytics/devguides/reporting/core/dimsmets>`_
391-

0 commit comments

Comments
 (0)