Skip to content

Commit 5803e4c

Browse files
SebastianRubbertjreback
authored andcommitted
consistent imports in text.rst
consistent imports in sparse.rst consistent imports in release.rst
1 parent 12df3ea commit 5803e4c

File tree

3 files changed

+42
-53
lines changed

3 files changed

+42
-53
lines changed

doc/source/release.rst

+6-14
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,13 @@
55
.. ipython:: python
66
:suppress:
77
8-
import os
9-
import csv
10-
from pandas.compat import StringIO
118
import pandas as pd
12-
ExcelWriter = pd.ExcelWriter
13-
149
import numpy as np
1510
np.random.seed(123456)
16-
randn = np.random.randn
1711
np.set_printoptions(precision=4, suppress=True)
18-
1912
import matplotlib.pyplot as plt
2013
plt.close('all')
2114
22-
from pandas import *
2315
options.display.max_rows=15
2416
import pandas.util.testing as tm
2517
@@ -1998,9 +1990,9 @@ Improvements to existing features
19981990

19991991
.. ipython:: python
20001992
2001-
p = Panel(randn(3,4,4),items=['ItemA','ItemB','ItemC'],
2002-
major_axis=date_range('20010102',periods=4),
2003-
minor_axis=['A','B','C','D'])
1993+
p = pd.Panel(np.random.randn(3,4,4),items=['ItemA','ItemB','ItemC'],
1994+
major_axis=pd.date_range('20010102',periods=4),
1995+
minor_axis=['A','B','C','D'])
20041996
p
20051997
p.reindex(items=['ItemA']).squeeze()
20061998
p.reindex(items=['ItemA'],minor=['B']).squeeze()
@@ -2016,11 +2008,11 @@ Improvements to existing features
20162008

20172009
.. ipython:: python
20182010
2019-
idx = date_range("2001-10-1", periods=5, freq='M')
2020-
ts = Series(np.random.rand(len(idx)),index=idx)
2011+
idx = pd.date_range("2001-10-1", periods=5, freq='M')
2012+
ts = pd.Series(np.random.rand(len(idx)),index=idx)
20212013
ts['2001']
20222014
2023-
df = DataFrame(dict(A = ts))
2015+
df = pd.DataFrame(dict(A = ts))
20242016
df['2001']
20252017
20262018
- added option `display.mpl_style` providing a sleeker visual style for plots. Based on https://gist.github.com/huyng/816622 (:issue:`3075`).

doc/source/sparse.rst

+17-20
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
77
import numpy as np
88
np.random.seed(123456)
9-
from pandas import *
9+
import pandas as pd
1010
import pandas.util.testing as tm
11-
randn = np.random.randn
1211
np.set_printoptions(precision=4, suppress=True)
1312
options.display.max_rows = 15
1413
@@ -26,7 +25,7 @@ method:
2625

2726
.. ipython:: python
2827
29-
ts = Series(randn(10))
28+
ts = pd.Series(randn(10))
3029
ts[2:-2] = np.nan
3130
sts = ts.to_sparse()
3231
sts
@@ -44,7 +43,7 @@ large, mostly NA DataFrame:
4443

4544
.. ipython:: python
4645
47-
df = DataFrame(randn(10000, 4))
46+
df = pd.DataFrame(randn(10000, 4))
4847
df.ix[:9998] = np.nan
4948
sdf = df.to_sparse()
5049
sdf
@@ -75,7 +74,7 @@ distinct from the ``fill_value``:
7574
7675
arr = np.random.randn(10)
7776
arr[2:5] = np.nan; arr[7:8] = np.nan
78-
sparr = SparseArray(arr)
77+
sparr = pd.SparseArray(arr)
7978
sparr
8079
8180
Like the indexed objects (SparseSeries, SparseDataFrame, SparsePanel), a
@@ -97,7 +96,7 @@ a ``fill_value`` (defaulting to ``NaN``):
9796

9897
.. ipython:: python
9998
100-
spl = SparseList()
99+
spl = pd.SparseList()
101100
spl
102101
103102
The two important methods are ``append`` and ``to_array``. ``append`` can
@@ -108,8 +107,7 @@ accept scalar values or any 1-dimensional sequence:
108107
109108
.. ipython:: python
110109
111-
from numpy import nan
112-
spl.append(np.array([1., nan, nan, 2., 3.]))
110+
spl.append(np.array([1., np.nan, np.nan, 2., 3.]))
113111
spl.append(5)
114112
spl.append(sparr)
115113
spl
@@ -149,15 +147,14 @@ The method requires a ``MultiIndex`` with two or more levels.
149147
150148
.. ipython:: python
151149
152-
from numpy import nan
153-
s = Series([3.0, nan, 1.0, 3.0, nan, nan])
154-
s.index = MultiIndex.from_tuples([(1, 2, 'a', 0),
155-
(1, 2, 'a', 1),
156-
(1, 1, 'b', 0),
157-
(1, 1, 'b', 1),
158-
(2, 1, 'b', 0),
159-
(2, 1, 'b', 1)],
160-
names=['A', 'B', 'C', 'D'])
150+
s = pd.Series([3.0, np.nan, 1.0, 3.0, np.nan, np.nan])
151+
s.index = pd.MultiIndex.from_tuples([(1, 2, 'a', 0),
152+
(1, 2, 'a', 1),
153+
(1, 1, 'b', 0),
154+
(1, 1, 'b', 1),
155+
(2, 1, 'b', 0),
156+
(2, 1, 'b', 1)],
157+
names=['A', 'B', 'C', 'D'])
161158
162159
s
163160
# SparseSeries
@@ -199,7 +196,7 @@ A convenience method :meth:`SparseSeries.from_coo` is implemented for creating a
199196
200197
from scipy import sparse
201198
A = sparse.coo_matrix(([3.0, 1.0, 2.0], ([1, 0, 0], [0, 2, 3])),
202-
shape=(3, 4))
199+
shape=(3, 4))
203200
A
204201
A.todense()
205202
@@ -208,7 +205,7 @@ only the non-null entries.
208205

209206
.. ipython:: python
210207
211-
ss = SparseSeries.from_coo(A)
208+
ss = pd.SparseSeries.from_coo(A)
212209
ss
213210
214211
Specifying ``dense_index=True`` will result in an index that is the Cartesian product of the
@@ -217,5 +214,5 @@ row and columns coordinates of the matrix. Note that this will consume a signifi
217214

218215
.. ipython:: python
219216
220-
ss_dense = SparseSeries.from_coo(A, dense_index=True)
217+
ss_dense = pd.SparseSeries.from_coo(A, dense_index=True)
221218
ss_dense

doc/source/text.rst

+19-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:suppress:
66
77
import numpy as np
8-
from pandas import *
8+
import pandas as pd
99
randn = np.random.randn
1010
np.set_printoptions(precision=4, suppress=True)
1111
from pandas.compat import lrange
@@ -25,14 +25,14 @@ the equivalent (scalar) built-in string methods:
2525

2626
.. ipython:: python
2727
28-
s = Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
28+
s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
2929
s.str.lower()
3030
s.str.upper()
3131
s.str.len()
3232
3333
.. ipython:: python
3434
35-
idx = Index([' jack', 'jill ', ' jesse ', 'frank'])
35+
idx = pd.Index([' jack', 'jill ', ' jesse ', 'frank'])
3636
idx.str.strip()
3737
idx.str.lstrip()
3838
idx.str.rstrip()
@@ -43,8 +43,8 @@ leading or trailing whitespace:
4343

4444
.. ipython:: python
4545
46-
df = DataFrame(randn(3, 2), columns=[' Column A ', ' Column B '],
47-
index=range(3))
46+
df = pd.DataFrame(randn(3, 2), columns=[' Column A ', ' Column B '],
47+
index=range(3))
4848
df
4949
5050
Since ``df.columns`` is an Index object, we can use the ``.str`` accessor
@@ -72,7 +72,7 @@ Methods like ``split`` return a Series of lists:
7272

7373
.. ipython:: python
7474
75-
s2 = Series(['a_b_c', 'c_d_e', np.nan, 'f_g_h'])
75+
s2 = pd.Series(['a_b_c', 'c_d_e', np.nan, 'f_g_h'])
7676
s2.str.split('_')
7777
7878
Elements in the split lists can be accessed using ``get`` or ``[]`` notation:
@@ -106,8 +106,8 @@ Methods like ``replace`` and ``findall`` take `regular expressions
106106

107107
.. ipython:: python
108108
109-
s3 = Series(['A', 'B', 'C', 'Aaba', 'Baca',
110-
'', np.nan, 'CABA', 'dog', 'cat'])
109+
s3 = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca',
110+
'', np.nan, 'CABA', 'dog', 'cat'])
111111
s3
112112
s3.str.replace('^.a|dog', 'XX-XX ', case=False)
113113
@@ -118,7 +118,7 @@ following code will cause trouble because of the regular expression meaning of
118118
.. ipython:: python
119119
120120
# Consider the following badly formatted financial data
121-
dollars = Series(['12', '-$10', '$10,000'])
121+
dollars = pd.Series(['12', '-$10', '$10,000'])
122122
123123
# This does what you'd naively expect:
124124
dollars.str.replace('$', '')
@@ -140,8 +140,8 @@ of the string, the result will be a ``NaN``.
140140

141141
.. ipython:: python
142142
143-
s = Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan,
144-
'CABA', 'dog', 'cat'])
143+
s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan,
144+
'CABA', 'dog', 'cat'])
145145
146146
s.str[0]
147147
s.str[1]
@@ -157,14 +157,14 @@ regular expression with one group returns a Series of strings.
157157

158158
.. ipython:: python
159159
160-
Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)')
160+
pd.Series(['a1', 'b2', 'c3']).str.extract('[ab](\d)')
161161
162162
Elements that do not match return ``NaN``. Extracting a regular expression
163163
with more than one group returns a DataFrame with one column per group.
164164

165165
.. ipython:: python
166166
167-
Series(['a1', 'b2', 'c3']).str.extract('([ab])(\d)')
167+
pd.Series(['a1', 'b2', 'c3']).str.extract('([ab])(\d)')
168168
169169
Elements that do not match return a row filled with ``NaN``.
170170
Thus, a Series of messy strings can be "converted" into a
@@ -178,13 +178,13 @@ Named groups like
178178

179179
.. ipython:: python
180180
181-
Series(['a1', 'b2', 'c3']).str.extract('(?P<letter>[ab])(?P<digit>\d)')
181+
pd.Series(['a1', 'b2', 'c3']).str.extract('(?P<letter>[ab])(?P<digit>\d)')
182182
183183
and optional groups like
184184

185185
.. ipython:: python
186186
187-
Series(['a1', 'b2', '3']).str.extract('(?P<letter>[ab])?(?P<digit>\d)')
187+
pd.Series(['a1', 'b2', '3']).str.extract('(?P<letter>[ab])?(?P<digit>\d)')
188188
189189
can also be used.
190190

@@ -196,14 +196,14 @@ You can check whether elements contain a pattern:
196196
.. ipython:: python
197197
198198
pattern = r'[a-z][0-9]'
199-
Series(['1', '2', '3a', '3b', '03c']).str.contains(pattern)
199+
pd.Series(['1', '2', '3a', '3b', '03c']).str.contains(pattern)
200200
201201
or match a pattern:
202202

203203

204204
.. ipython:: python
205205
206-
Series(['1', '2', '3a', '3b', '03c']).str.match(pattern, as_indexer=True)
206+
pd.Series(['1', '2', '3a', '3b', '03c']).str.match(pattern, as_indexer=True)
207207
208208
The distinction between ``match`` and ``contains`` is strictness: ``match``
209209
relies on strict ``re.match``, while ``contains`` relies on ``re.search``.
@@ -225,7 +225,7 @@ Methods like ``match``, ``contains``, ``startswith``, and ``endswith`` take
225225

226226
.. ipython:: python
227227
228-
s4 = Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
228+
s4 = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
229229
s4.str.contains('A', na=False)
230230
231231
Creating Indicator Variables
@@ -236,7 +236,7 @@ For example if they are separated by a ``'|'``:
236236

237237
.. ipython:: python
238238
239-
s = Series(['a', 'a|b', np.nan, 'a|c'])
239+
s = pd.Series(['a', 'a|b', np.nan, 'a|c'])
240240
s.str.get_dummies(sep='|')
241241
242242
See also :func:`~pandas.get_dummies`.

0 commit comments

Comments
 (0)