Skip to content

Commit 90c4d53

Browse files
committed
added pd as namespace
more consistent with code in the rest of the document added more namespace Generally, also numpy's randn should used as np.random.randn isolated namespace changes removed warning on hdf groups remaining namespace
1 parent ed3d145 commit 90c4d53

File tree

1 file changed

+45
-46
lines changed

1 file changed

+45
-46
lines changed

doc/source/io.rst

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919
import matplotlib.pyplot as plt
2020
plt.close('all')
2121
22-
from pandas import *
2322
options.display.max_rows=15
2423
import pandas.util.testing as tm
25-
clipdf = DataFrame({'A':[1,2,3],'B':[4,5,6],'C':['p','q','r']},
24+
clipdf = pd.DataFrame({'A':[1,2,3],'B':[4,5,6],'C':['p','q','r']},
2625
index=['x','y','z'])
2726
2827
===============================
@@ -1195,7 +1194,7 @@ class of the csv module. For this, you have to specify ``sep=None``.
11951194
.. ipython:: python
11961195
:suppress:
11971196
1198-
df = DataFrame(np.random.randn(10, 4))
1197+
df = pd.DataFrame(np.random.randn(10, 4))
11991198
df.to_csv('tmp.sv', sep='|')
12001199
df.to_csv('tmp2.sv', sep=':')
12011200
@@ -1375,7 +1374,7 @@ Note ``NaN``'s, ``NaT``'s and ``None`` will be converted to ``null`` and ``datet
13751374

13761375
.. ipython:: python
13771376
1378-
dfj = DataFrame(randn(5, 2), columns=list('AB'))
1377+
dfj = pd.DataFrame(randn(5, 2), columns=list('AB'))
13791378
json = dfj.to_json()
13801379
json
13811380
@@ -1387,10 +1386,10 @@ file / string. Consider the following DataFrame and Series:
13871386

13881387
.. ipython:: python
13891388
1390-
dfjo = DataFrame(dict(A=range(1, 4), B=range(4, 7), C=range(7, 10)),
1389+
dfjo = pd.DataFrame(dict(A=range(1, 4), B=range(4, 7), C=range(7, 10)),
13911390
columns=list('ABC'), index=list('xyz'))
13921391
dfjo
1393-
sjo = Series(dict(x=15, y=16, z=17), name='D')
1392+
sjo = pd.Series(dict(x=15, y=16, z=17), name='D')
13941393
sjo
13951394
13961395
**Column oriented** (the default for ``DataFrame``) serializes the data as
@@ -1472,10 +1471,10 @@ Writing to a file, with a date index and a date column
14721471
.. ipython:: python
14731472
14741473
dfj2 = dfj.copy()
1475-
dfj2['date'] = Timestamp('20130101')
1474+
dfj2['date'] = pd.Timestamp('20130101')
14761475
dfj2['ints'] = list(range(5))
14771476
dfj2['bools'] = True
1478-
dfj2.index = date_range('20130101', periods=5)
1477+
dfj2.index = pd.date_range('20130101', periods=5)
14791478
dfj2.to_json('test.json')
14801479
open('test.json').read()
14811480
@@ -1506,7 +1505,7 @@ problems:
15061505
15071506
In [141]: from datetime import timedelta
15081507
1509-
In [142]: dftd = DataFrame([timedelta(23), timedelta(seconds=5), 42])
1508+
In [142]: dftd = pd.DataFrame([timedelta(23), timedelta(seconds=5), 42])
15101509
15111510
In [143]: dftd.to_json()
15121511
@@ -1633,7 +1632,7 @@ Preserve string indices:
16331632

16341633
.. ipython:: python
16351634
1636-
si = DataFrame(np.zeros((4, 4)),
1635+
si = pd.DataFrame(np.zeros((4, 4)),
16371636
columns=list(range(4)),
16381637
index=[str(i) for i in range(4)])
16391638
si
@@ -1681,7 +1680,7 @@ data:
16811680
16821681
randfloats = np.random.uniform(-100, 1000, 10000)
16831682
randfloats.shape = (1000, 10)
1684-
dffloats = DataFrame(randfloats, columns=list('ABCDEFGHIJ'))
1683+
dffloats = pd.DataFrame(randfloats, columns=list('ABCDEFGHIJ'))
16851684
16861685
jsonfloats = dffloats.to_json()
16871686
@@ -1884,7 +1883,7 @@ Read in pandas ``to_html`` output (with some loss of floating point precision)
18841883

18851884
.. code-block:: python
18861885
1887-
df = DataFrame(randn(2, 2))
1886+
df = pd.DataFrame(randn(2, 2))
18881887
s = df.to_html(float_format='{0:.40g}'.format)
18891888
dfin = read_html(s, index_col=0)
18901889
@@ -1937,7 +1936,7 @@ in the method ``to_string`` described above.
19371936
19381937
.. ipython:: python
19391938
1940-
df = DataFrame(randn(2, 2))
1939+
df = pd.DataFrame(randn(2, 2))
19411940
df
19421941
print(df.to_html()) # raw html
19431942
@@ -2013,7 +2012,7 @@ Finally, the ``escape`` argument allows you to control whether the
20132012

20142013
.. ipython:: python
20152014
2016-
df = DataFrame({'a': list('&<>'), 'b': randn(3)})
2015+
df = pd.DataFrame({'a': list('&<>'), 'b': randn(3)})
20172016
20182017
20192018
.. ipython:: python
@@ -2367,7 +2366,7 @@ Added support for Openpyxl >= 2.2
23672366
bio = BytesIO()
23682367
23692368
# By setting the 'engine' in the ExcelWriter constructor.
2370-
writer = ExcelWriter(bio, engine='xlsxwriter')
2369+
writer = pd.ExcelWriter(bio, engine='xlsxwriter')
23712370
df.to_excel(writer, sheet_name='Sheet1')
23722371
23732372
# Save the workbook
@@ -2423,7 +2422,7 @@ argument to ``to_excel`` and to ``ExcelWriter``. The built-in engines are:
24232422
df.to_excel('path_to_file.xlsx', sheet_name='Sheet1', engine='xlsxwriter')
24242423
24252424
# By setting the 'engine' in the ExcelWriter constructor.
2426-
writer = ExcelWriter('path_to_file.xlsx', engine='xlsxwriter')
2425+
writer = pd.ExcelWriter('path_to_file.xlsx', engine='xlsxwriter')
24272426
24282427
# Or via pandas configuration.
24292428
from pandas import options
@@ -2559,7 +2558,7 @@ both on the writing (serialization), and reading (deserialization).
25592558

25602559
.. ipython:: python
25612560
2562-
df = DataFrame(np.random.rand(5,2),columns=list('AB'))
2561+
df = pd.DataFrame(np.random.rand(5,2),columns=list('AB'))
25632562
df.to_msgpack('foo.msg')
25642563
pd.read_msgpack('foo.msg')
25652564
s = Series(np.random.rand(5),index=date_range('20130101',periods=5))
@@ -2647,7 +2646,7 @@ for some advanced strategies
26472646
26482647
.. ipython:: python
26492648
2650-
store = HDFStore('store.h5')
2649+
store = pd.HDFStore('store.h5')
26512650
print(store)
26522651
26532652
Objects can be written to the file just like adding key-value pairs to a
@@ -2656,11 +2655,11 @@ dict:
26562655
.. ipython:: python
26572656
26582657
np.random.seed(1234)
2659-
index = date_range('1/1/2000', periods=8)
2660-
s = Series(randn(5), index=['a', 'b', 'c', 'd', 'e'])
2661-
df = DataFrame(randn(8, 3), index=index,
2658+
index = pd.date_range('1/1/2000', periods=8)
2659+
s = pd.Series(randn(5), index=['a', 'b', 'c', 'd', 'e'])
2660+
df = pd.DataFrame(randn(8, 3), index=index,
26622661
columns=['A', 'B', 'C'])
2663-
wp = Panel(randn(2, 5, 4), items=['Item1', 'Item2'],
2662+
wp = pd.Panel(randn(2, 5, 4), items=['Item1', 'Item2'],
26642663
major_axis=date_range('1/1/2000', periods=5),
26652664
minor_axis=['A', 'B', 'C', 'D'])
26662665
@@ -2705,7 +2704,7 @@ Closing a Store, Context Manager
27052704
27062705
# Working with, and automatically closing the store with the context
27072706
# manager
2708-
with HDFStore('store.h5') as store:
2707+
with pd.HDFStore('store.h5') as store:
27092708
store.keys()
27102709
27112710
.. ipython:: python
@@ -2772,7 +2771,7 @@ This is also true for the major axis of a ``Panel``:
27722771
[[np.nan, np.nan, np.nan], [np.nan,5,6]],
27732772
[[np.nan, np.nan, np.nan],[np.nan,3,np.nan]]]
27742773
2775-
panel_with_major_axis_all_missing = Panel(matrix,
2774+
panel_with_major_axis_all_missing = pd.Panel(matrix,
27762775
items=['Item1', 'Item2','Item3'],
27772776
major_axis=[1,2],
27782777
minor_axis=['A', 'B', 'C'])
@@ -2816,7 +2815,7 @@ This format is specified by default when using ``put`` or ``to_hdf`` or by ``for
28162815

28172816
.. code-block:: python
28182817
2819-
DataFrame(randn(10,2)).to_hdf('test_fixed.h5','df')
2818+
pd.DataFrame(randn(10,2)).to_hdf('test_fixed.h5','df')
28202819
28212820
pd.read_hdf('test_fixed.h5','df',where='index>5')
28222821
TypeError: cannot pass a where specification when reading a fixed format.
@@ -2848,7 +2847,7 @@ enable ``put/append/to_hdf`` to by default store in the ``table`` format.
28482847
28492848
.. ipython:: python
28502849
2851-
store = HDFStore('store.h5')
2850+
store = pd.HDFStore('store.h5')
28522851
df1 = df[0:4]
28532852
df2 = df[4:]
28542853
@@ -2914,7 +2913,7 @@ defaults to `nan`.
29142913

29152914
.. ipython:: python
29162915
2917-
df_mixed = DataFrame({ 'A' : randn(8),
2916+
df_mixed = pd.DataFrame({ 'A' : randn(8),
29182917
'B' : randn(8),
29192918
'C' : np.array(randn(8),dtype='float32'),
29202919
'string' :'string',
@@ -2940,12 +2939,12 @@ storing/selecting from homogeneous index DataFrames.
29402939

29412940
.. ipython:: python
29422941
2943-
index = MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
2942+
index = pd.MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],
29442943
['one', 'two', 'three']],
29452944
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],
29462945
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],
29472946
names=['foo', 'bar'])
2948-
df_mi = DataFrame(np.random.randn(10, 3), index=index,
2947+
df_mi = pd.DataFrame(np.random.randn(10, 3), index=index,
29492948
columns=['A', 'B', 'C'])
29502949
df_mi
29512950
@@ -3127,7 +3126,7 @@ specified in the format: ``<float>(<unit>)``, where float may be signed (and fra
31273126
.. ipython:: python
31283127
31293128
from datetime import timedelta
3130-
dftd = DataFrame(dict(A = Timestamp('20130101'), B = [ Timestamp('20130101') + timedelta(days=i,seconds=10) for i in range(10) ]))
3129+
dftd = pd.DataFrame(dict(A = Timestamp('20130101'), B = [ Timestamp('20130101') + timedelta(days=i,seconds=10) for i in range(10) ]))
31313130
dftd['C'] = dftd['A']-dftd['B']
31323131
dftd
31333132
store.append('dftd',dftd,data_columns=True)
@@ -3163,8 +3162,8 @@ Oftentimes when appending large amounts of data to a store, it is useful to turn
31633162

31643163
.. ipython:: python
31653164
3166-
df_1 = DataFrame(randn(10,2),columns=list('AB'))
3167-
df_2 = DataFrame(randn(10,2),columns=list('AB'))
3165+
df_1 = pd.DataFrame(randn(10,2),columns=list('AB'))
3166+
df_2 = pd.DataFrame(randn(10,2),columns=list('AB'))
31683167
31693168
st = pd.HDFStore('appends.h5',mode='w')
31703169
st.append('df', df_1, data_columns=['B'], index=False)
@@ -3261,7 +3260,7 @@ chunks.
32613260

32623261
.. ipython:: python
32633262
3264-
dfeq = DataFrame({'number': np.arange(1,11)})
3263+
dfeq = pd.DataFrame({'number': np.arange(1,11)})
32653264
dfeq
32663265
32673266
store.append('dfeq', dfeq, data_columns=['number'])
@@ -3301,7 +3300,7 @@ Sometimes you want to get the coordinates (a.k.a the index locations) of your qu
33013300

33023301
.. ipython:: python
33033302
3304-
df_coord = DataFrame(np.random.randn(1000,2),index=date_range('20000101',periods=1000))
3303+
df_coord = pd.DataFrame(np.random.randn(1000,2),index=date_range('20000101',periods=1000))
33053304
store.append('df_coord',df_coord)
33063305
c = store.select_as_coordinates('df_coord','index>20020101')
33073306
c.summary()
@@ -3318,7 +3317,7 @@ a datetimeindex which are 5.
33183317

33193318
.. ipython:: python
33203319
3321-
df_mask = DataFrame(np.random.randn(1000,2),index=date_range('20000101',periods=1000))
3320+
df_mask = pd.DataFrame(np.random.randn(1000,2),index=date_range('20000101',periods=1000))
33223321
store.append('df_mask',df_mask)
33233322
c = store.select_column('df_mask','index')
33243323
where = c[DatetimeIndex(c).month==5].index
@@ -3366,7 +3365,7 @@ results.
33663365

33673366
.. ipython:: python
33683367
3369-
df_mt = DataFrame(randn(8, 6), index=date_range('1/1/2000', periods=8),
3368+
df_mt = pd.DataFrame(randn(8, 6), index=date_range('1/1/2000', periods=8),
33703369
columns=['A', 'B', 'C', 'D', 'E', 'F'])
33713370
df_mt['foo'] = 'bar'
33723371
df_mt.ix[1, ('A', 'B')] = np.nan
@@ -3458,7 +3457,7 @@ Compression for all objects within the file
34583457

34593458
.. code-block:: python
34603459
3461-
store_compressed = HDFStore('store_compressed.h5', complevel=9, complib='blosc')
3460+
store_compressed = pd.HDFStore('store_compressed.h5', complevel=9, complib='blosc')
34623461
34633462
Or on-the-fly compression (this only applies to tables). You can turn
34643463
off file compression for a specific table by passing ``complevel=0``
@@ -3556,7 +3555,7 @@ stored in a more efficient manner.
35563555

35573556
.. ipython:: python
35583557
3559-
dfcat = DataFrame({ 'A' : Series(list('aabbcdba')).astype('category'),
3558+
dfcat = pd.DataFrame({ 'A' : Series(list('aabbcdba')).astype('category'),
35603559
'B' : np.random.randn(8) })
35613560
dfcat
35623561
dfcat.dtypes
@@ -3614,7 +3613,7 @@ Starting in 0.11.0, passing a ``min_itemsize`` dict will cause all passed column
36143613

36153614
.. ipython:: python
36163615
3617-
dfs = DataFrame(dict(A = 'foo', B = 'bar'),index=list(range(5)))
3616+
dfs = pd.DataFrame(dict(A = 'foo', B = 'bar'),index=list(range(5)))
36183617
dfs
36193618
36203619
# A and B have a size of 30
@@ -3633,7 +3632,7 @@ You could inadvertently turn an actual ``nan`` value into a missing value.
36333632

36343633
.. ipython:: python
36353634
3636-
dfss = DataFrame(dict(A = ['foo','bar','nan']))
3635+
dfss = pd.DataFrame(dict(A = ['foo','bar','nan']))
36373636
dfss
36383637
36393638
store.append('dfss', dfss)
@@ -3667,7 +3666,7 @@ It is possible to write an ``HDFStore`` object that can easily be imported into
36673666
index=range(100))
36683667
df_for_r.head()
36693668
3670-
store_export = HDFStore('export.h5')
3669+
store_export = pd.HDFStore('export.h5')
36713670
store_export.append('df_for_r', df_for_r, data_columns=df_dc.columns)
36723671
store_export
36733672
@@ -3756,7 +3755,7 @@ number of options, please see the docstring.
37563755
.. ipython:: python
37573756
37583757
# a legacy store
3759-
legacy_store = HDFStore(legacy_file_path,'r')
3758+
legacy_store = pd.HDFStore(legacy_file_path,'r')
37603759
legacy_store
37613760
37623761
# copy (and return the new handle)
@@ -3920,7 +3919,7 @@ the database using :func:`~pandas.DataFrame.to_sql`.
39203919
(42, datetime.datetime(2010,10,19), 'Y', -12.5, False),
39213920
(63, datetime.datetime(2010,10,20), 'Z', 5.73, True)]
39223921
3923-
data = DataFrame(d, columns=c)
3922+
data = pd.DataFrame(d, columns=c)
39243923
39253924
.. ipython:: python
39263925
@@ -4400,7 +4399,7 @@ into a .dta file. The format version of this file is always 115 (Stata 12).
44004399

44014400
.. ipython:: python
44024401
4403-
df = DataFrame(randn(10, 2), columns=list('AB'))
4402+
df = pd.DataFrame(randn(10, 2), columns=list('AB'))
44044403
df.to_stata('stata.dta')
44054404
44064405
*Stata* data files have limited data type support; only strings with
@@ -4625,7 +4624,7 @@ This is an informal comparison of various IO methods, using pandas 0.13.1.
46254624

46264625
.. code-block:: python
46274626
4628-
In [1]: df = DataFrame(randn(1000000,2),columns=list('AB'))
4627+
In [1]: df = pd.DataFrame(randn(1000000,2),columns=list('AB'))
46294628
46304629
In [2]: df.info()
46314630
<class 'pandas.core.frame.DataFrame'>
@@ -4699,7 +4698,7 @@ And here's the code
46994698
import os
47004699
from pandas.io import sql
47014700
4702-
df = DataFrame(randn(1000000,2),columns=list('AB'))
4701+
df = pd.DataFrame(randn(1000000,2),columns=list('AB'))
47034702
47044703
def test_sql_write(df):
47054704
if os.path.exists('test.sql'):

0 commit comments

Comments
 (0)