Skip to content

Commit c6cf596

Browse files
Merge pull request #9987 from jorisvandenbossche/doc-imports
DOC: clean up / consistent imports (GH9886)
2 parents 2cb7414 + 25dc280 commit c6cf596

File tree

4 files changed

+159
-203
lines changed

4 files changed

+159
-203
lines changed

doc/source/computation.rst

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
.. currentmodule:: pandas
2-
.. _computation:
32

43
.. ipython:: python
54
:suppress:
65
76
import numpy as np
87
np.random.seed(123456)
9-
from pandas import *
10-
import pandas.util.testing as tm
11-
randn = np.random.randn
128
np.set_printoptions(precision=4, suppress=True)
9+
import pandas as pd
1310
import matplotlib
1411
try:
1512
matplotlib.style.use('ggplot')
1613
except AttributeError:
17-
options.display.mpl_style = 'default'
14+
pd.options.display.mpl_style = 'default'
1815
import matplotlib.pyplot as plt
1916
plt.close('all')
20-
options.display.max_rows=15
17+
pd.options.display.max_rows=15
18+
19+
.. _computation:
2120

2221
Computational tools
2322
===================
@@ -36,13 +35,13 @@ NA/null values *before* computing the percent change).
3635

3736
.. ipython:: python
3837
39-
ser = Series(randn(8))
38+
ser = pd.Series(np.random.randn(8))
4039
4140
ser.pct_change()
4241
4342
.. ipython:: python
4443
45-
df = DataFrame(randn(10, 4))
44+
df = pd.DataFrame(np.random.randn(10, 4))
4645
4746
df.pct_change(periods=3)
4847
@@ -56,8 +55,8 @@ The ``Series`` object has a method ``cov`` to compute covariance between series
5655

5756
.. ipython:: python
5857
59-
s1 = Series(randn(1000))
60-
s2 = Series(randn(1000))
58+
s1 = pd.Series(np.random.randn(1000))
59+
s2 = pd.Series(np.random.randn(1000))
6160
s1.cov(s2)
6261
6362
Analogously, ``DataFrame`` has a method ``cov`` to compute pairwise covariances
@@ -78,7 +77,7 @@ among the series in the DataFrame, also excluding NA/null values.
7877

7978
.. ipython:: python
8079
81-
frame = DataFrame(randn(1000, 5), columns=['a', 'b', 'c', 'd', 'e'])
80+
frame = pd.DataFrame(np.random.randn(1000, 5), columns=['a', 'b', 'c', 'd', 'e'])
8281
frame.cov()
8382
8483
``DataFrame.cov`` also supports an optional ``min_periods`` keyword that
@@ -87,7 +86,7 @@ in order to have a valid result.
8786

8887
.. ipython:: python
8988
90-
frame = DataFrame(randn(20, 3), columns=['a', 'b', 'c'])
89+
frame = pd.DataFrame(np.random.randn(20, 3), columns=['a', 'b', 'c'])
9190
frame.ix[:5, 'a'] = np.nan
9291
frame.ix[5:10, 'b'] = np.nan
9392
@@ -123,7 +122,7 @@ All of these are currently computed using pairwise complete observations.
123122

124123
.. ipython:: python
125124
126-
frame = DataFrame(randn(1000, 5), columns=['a', 'b', 'c', 'd', 'e'])
125+
frame = pd.DataFrame(np.random.randn(1000, 5), columns=['a', 'b', 'c', 'd', 'e'])
127126
frame.ix[::2] = np.nan
128127
129128
# Series with Series
@@ -140,7 +139,7 @@ Like ``cov``, ``corr`` also supports the optional ``min_periods`` keyword:
140139

141140
.. ipython:: python
142141
143-
frame = DataFrame(randn(20, 3), columns=['a', 'b', 'c'])
142+
frame = pd.DataFrame(np.random.randn(20, 3), columns=['a', 'b', 'c'])
144143
frame.ix[:5, 'a'] = np.nan
145144
frame.ix[5:10, 'b'] = np.nan
146145
@@ -157,8 +156,8 @@ objects.
157156
158157
index = ['a', 'b', 'c', 'd', 'e']
159158
columns = ['one', 'two', 'three', 'four']
160-
df1 = DataFrame(randn(5, 4), index=index, columns=columns)
161-
df2 = DataFrame(randn(4, 4), index=index[:4], columns=columns)
159+
df1 = pd.DataFrame(np.random.randn(5, 4), index=index, columns=columns)
160+
df2 = pd.DataFrame(np.random.randn(4, 4), index=index[:4], columns=columns)
162161
df1.corrwith(df2)
163162
df2.corrwith(df1, axis=1)
164163
@@ -172,7 +171,7 @@ of the ranks (by default) for the group:
172171

173172
.. ipython:: python
174173
175-
s = Series(np.random.randn(5), index=list('abcde'))
174+
s = pd.Series(np.random.np.random.randn(5), index=list('abcde'))
176175
s['d'] = s['b'] # so there's a tie
177176
s.rank()
178177
@@ -181,7 +180,7 @@ or the columns (``axis=1``). ``NaN`` values are excluded from the ranking.
181180

182181
.. ipython:: python
183182
184-
df = DataFrame(np.random.randn(10, 6))
183+
df = pd.DataFrame(np.random.np.random.randn(10, 6))
185184
df[4] = df[2][:5] # some ties
186185
df
187186
df.rank(1)
@@ -253,7 +252,7 @@ These functions can be applied to ndarrays or Series objects:
253252

254253
.. ipython:: python
255254
256-
ts = Series(randn(1000), index=date_range('1/1/2000', periods=1000))
255+
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
257256
ts = ts.cumsum()
258257
259258
ts.plot(style='k--')
@@ -271,7 +270,7 @@ sugar for applying the moving window operator to all of the DataFrame's columns:
271270
272271
.. ipython:: python
273272
274-
df = DataFrame(randn(1000, 4), index=ts.index,
273+
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index,
275274
columns=['A', 'B', 'C', 'D'])
276275
df = df.cumsum()
277276
@@ -310,7 +309,7 @@ keyword. The list of recognized types are:
310309

311310
.. ipython:: python
312311
313-
ser = Series(randn(10), index=date_range('1/1/2000', periods=10))
312+
ser = pd.Series(np.random.randn(10), index=pd.date_range('1/1/2000', periods=10))
314313
315314
rolling_window(ser, 5, 'triang')
316315

0 commit comments

Comments
 (0)