Skip to content

Commit 527db38

Browse files
committed
DOC: 10min import fixes
1 parent f1bac6f commit 527db38

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

doc/source/10min.rst

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,16 @@
99
import random
1010
import os
1111
np.random.seed(123456)
12-
from pandas import *
12+
from pandas import options
1313
import pandas as pd
14-
randn = np.random.randn
15-
randint = np.random.randint
1614
np.set_printoptions(precision=4, suppress=True)
1715
options.display.mpl_style='default'
1816
from pandas.compat import lrange, lzip
1917
2018
#### portions of this were borrowed from the
21-
#### Pandas cheatsheet
22-
#### created during the PyData Workshop-Sprint 2012
23-
#### Hannah Chen, Henry Chow, Eric Cox, Robert Mauriello
19+
#### Pandas cheatsheet
20+
#### created during the PyData Workshop-Sprint 2012
21+
#### Hannah Chen, Henry Chow, Eric Cox, Robert Mauriello
2422
2523
2624
********************
@@ -42,7 +40,7 @@ Object Creation
4240

4341
See the :ref:`Data Structure Intro section <dsintro>`
4442

45-
Creating a ``Series`` by passing a list of values, letting pandas create a default
43+
Creating a ``Series`` by passing a list of values, letting pandas create a default
4644
integer index
4745

4846
.. ipython:: python
@@ -63,10 +61,10 @@ Creating a ``DataFrame`` by passing a dict of objects that can be converted to s
6361

6462
.. ipython:: python
6563
66-
df2 = pd.DataFrame({ 'A' : 1.,
67-
'B' : pd.Timestamp('20130102'),
64+
df2 = pd.DataFrame({ 'A' : 1.,
65+
'B' : pd.Timestamp('20130102'),
6866
'C' : pd.Series(1,index=lrange(4),dtype='float32'),
69-
'D' : np.array([3] * 4,dtype='int32'),
67+
'D' : np.array([3] * 4,dtype='int32'),
7068
'E' : 'foo' })
7169
df2
7270
@@ -123,7 +121,7 @@ Sorting by values
123121
Selection
124122
---------
125123

126-
.. note::
124+
.. note::
127125

128126
While standard Python / Numpy expressions for selecting and setting are
129127
intuitive and come in handy for interactive work, for production code, we
@@ -248,7 +246,7 @@ error.
248246
x[4:10]
249247
x[8:10]
250248
251-
Pandas will detect this and raise ``IndexError``, rather than return an empty
249+
Pandas will detect this and raise ``IndexError``, rather than return an empty
252250
structure.
253251

254252
::
@@ -280,7 +278,7 @@ by the indexes
280278

281279
.. ipython:: python
282280
283-
s1 = pd.Series([1,2,3,4,5,6],index=date_range('20130102',periods=6))
281+
s1 = pd.Series([1,2,3,4,5,6],index=pd.date_range('20130102',periods=6))
284282
s1
285283
df['F'] = s1
286284
@@ -401,7 +399,7 @@ See more at :ref:`Histogramming and Discretization <basics.discretization>`
401399

402400
.. ipython:: python
403401
404-
s = Series(np.random.randint(0,7,size=10))
402+
s = pd.Series(np.random.randint(0,7,size=10))
405403
s
406404
s.value_counts()
407405
@@ -412,7 +410,7 @@ See more at :ref:`Vectorized String Methods <basics.string_methods>`
412410

413411
.. ipython:: python
414412
415-
s = Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
413+
s = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca', np.nan, 'CABA', 'dog', 'cat'])
416414
s.str.lower()
417415
418416
Merge
@@ -428,7 +426,7 @@ operations.
428426

429427
See the :ref:`Merging section <merging>`
430428

431-
Concatenating pandas objects together
429+
Concatenating pandas objects together
432430

433431
.. ipython:: python
434432
@@ -438,7 +436,7 @@ Concatenating pandas objects together
438436
# break it into pieces
439437
pieces = [df[:3], df[3:7], df[7:]]
440438
441-
concat(pieces)
439+
pd.concat(pieces)
442440
443441
Join
444442
~~~~
@@ -451,7 +449,7 @@ SQL style merges. See the :ref:`Database style joining <merging.join>`
451449
right = pd.DataFrame({'key': ['foo', 'foo'], 'rval': [4, 5]})
452450
left
453451
right
454-
merge(left, right, on='key')
452+
pd.merge(left, right, on='key')
455453
456454
Append
457455
~~~~~~
@@ -484,7 +482,8 @@ See the :ref:`Grouping section <groupby>`
484482
'foo', 'bar', 'foo', 'foo'],
485483
'B' : ['one', 'one', 'two', 'three',
486484
'two', 'two', 'one', 'three'],
487-
'C' : randn(8), 'D' : randn(8)})
485+
'C' : np.random.randn(8),
486+
'D' : np.random.randn(8)})
488487
df
489488
490489
Grouping and then applying a function ``sum`` to the resulting groups.
@@ -493,7 +492,7 @@ Grouping and then applying a function ``sum`` to the resulting groups.
493492
494493
df.groupby('A').sum()
495494
496-
Grouping by multiple columns forms a hierarchical index, which we then apply
495+
Grouping by multiple columns forms a hierarchical index, which we then apply
497496
the function.
498497

499498
.. ipython:: python
@@ -516,7 +515,7 @@ Stack
516515
['one', 'two', 'one', 'two',
517516
'one', 'two', 'one', 'two']])
518517
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
519-
df = pd.DataFrame(randn(8, 2), index=index, columns=['A', 'B'])
518+
df = pd.DataFrame(np.random.randn(8, 2), index=index, columns=['A', 'B'])
520519
df2 = df[:4]
521520
df2
522521
@@ -543,18 +542,18 @@ See the section on :ref:`Pivot Tables <reshaping.pivot>`.
543542

544543
.. ipython:: python
545544
546-
df = DataFrame({'A' : ['one', 'one', 'two', 'three'] * 3,
547-
'B' : ['A', 'B', 'C'] * 4,
548-
'C' : ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
549-
'D' : np.random.randn(12),
550-
'E' : np.random.randn(12)})
545+
df = pd.DataFrame({'A' : ['one', 'one', 'two', 'three'] * 3,
546+
'B' : ['A', 'B', 'C'] * 4,
547+
'C' : ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
548+
'D' : np.random.randn(12),
549+
'E' : np.random.randn(12)})
551550
df
552551
553552
We can produce pivot tables from this data very easily:
554553

555554
.. ipython:: python
556555
557-
pivot_table(df, values='D', rows=['A', 'B'], cols=['C'])
556+
pd.pivot_table(df, values='D', rows=['A', 'B'], cols=['C'])
558557
559558
560559
Time Series
@@ -568,15 +567,15 @@ financial applications. See the :ref:`Time Series section <timeseries>`
568567
.. ipython:: python
569568
570569
rng = pd.date_range('1/1/2012', periods=100, freq='S')
571-
ts = pd.Series(randint(0, 500, len(rng)), index=rng)
570+
ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng)
572571
ts.resample('5Min', how='sum')
573572
574573
Time zone representation
575574

576575
.. ipython:: python
577576
578577
rng = pd.date_range('3/6/2012 00:00', periods=5, freq='D')
579-
ts = pd.Series(randn(len(rng)), rng)
578+
ts = pd.Series(np.random.randn(len(rng)), rng)
580579
ts_utc = ts.tz_localize('UTC')
581580
ts_utc
582581
@@ -591,7 +590,7 @@ Converting between time span representations
591590
.. ipython:: python
592591
593592
rng = pd.date_range('1/1/2012', periods=5, freq='M')
594-
ts = pd.Series(randn(len(rng)), index=rng)
593+
ts = pd.Series(np.random.randn(len(rng)), index=rng)
595594
ts
596595
ps = ts.to_period()
597596
ps
@@ -604,8 +603,8 @@ the quarter end:
604603

605604
.. ipython:: python
606605
607-
prng = period_range('1990Q1', '2000Q4', freq='Q-NOV')
608-
ts = Series(randn(len(prng)), prng)
606+
prng = pd.period_range('1990Q1', '2000Q4', freq='Q-NOV')
607+
ts = pd.Series(np.random.randn(len(prng)), prng)
609608
ts.index = (prng.asfreq('M', 'e') + 1).asfreq('H', 's') + 9
610609
ts.head()
611610
@@ -624,7 +623,7 @@ Plotting
624623
625624
.. ipython:: python
626625
627-
ts = pd.Series(randn(1000), index=pd.date_range('1/1/2000', periods=1000))
626+
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
628627
ts = ts.cumsum()
629628
630629
@savefig series_plot_basic.png
@@ -634,7 +633,7 @@ On DataFrame, ``plot`` is a convenience to plot all of the columns with labels:
634633

635634
.. ipython:: python
636635
637-
df = pd.DataFrame(randn(1000, 4), index=ts.index,
636+
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index,
638637
columns=['A', 'B', 'C', 'D'])
639638
df = df.cumsum()
640639
@@ -679,7 +678,7 @@ Reading from a HDF5 Store
679678

680679
.. ipython:: python
681680
682-
read_hdf('foo.h5','df')
681+
pd.read_hdf('foo.h5','df')
683682
684683
.. ipython:: python
685684
:suppress:
@@ -701,7 +700,7 @@ Reading from an excel file
701700

702701
.. ipython:: python
703702
704-
read_excel('foo.xlsx', 'sheet1', index_col=None, na_values=['NA'])
703+
pd.read_excel('foo.xlsx', 'sheet1', index_col=None, na_values=['NA'])
705704
706705
.. ipython:: python
707706
:suppress:

0 commit comments

Comments
 (0)