|
14 | 14 | from pandas.compat import StringIO, BytesIO
|
15 | 15 |
|
16 | 16 |
|
17 |
| - randn = np.random.randn |
18 | 17 | np.set_printoptions(precision=4, suppress=True)
|
19 | 18 | plt.close('all')
|
20 | 19 | pd.options.display.max_rows = 15
|
@@ -1767,7 +1766,7 @@ Note ``NaN``'s, ``NaT``'s and ``None`` will be converted to ``null`` and ``datet
|
1767 | 1766 |
|
1768 | 1767 | .. ipython:: python
|
1769 | 1768 |
|
1770 |
| - dfj = pd.DataFrame(randn(5, 2), columns=list('AB')) |
| 1769 | + dfj = pd.DataFrame(np.random.randn(5, 2), columns=list('AB')) |
1771 | 1770 | json = dfj.to_json()
|
1772 | 1771 | json
|
1773 | 1772 |
|
@@ -1842,7 +1841,7 @@ Writing in ISO date format:
|
1842 | 1841 |
|
1843 | 1842 | .. ipython:: python
|
1844 | 1843 |
|
1845 |
| - dfd = pd.DataFrame(randn(5, 2), columns=list('AB')) |
| 1844 | + dfd = pd.DataFrame(np.random.randn(5, 2), columns=list('AB')) |
1846 | 1845 | dfd['date'] = pd.Timestamp('20130101')
|
1847 | 1846 | dfd = dfd.sort_index(1, ascending=False)
|
1848 | 1847 | json = dfd.to_json(date_format='iso')
|
@@ -2482,7 +2481,7 @@ Read in pandas ``to_html`` output (with some loss of floating point precision):
|
2482 | 2481 |
|
2483 | 2482 | .. code-block:: python
|
2484 | 2483 |
|
2485 |
| - df = pd.DataFrame(randn(2, 2)) |
| 2484 | + df = pd.DataFrame(np.random.randn(2, 2)) |
2486 | 2485 | s = df.to_html(float_format='{0:.40g}'.format)
|
2487 | 2486 | dfin = pd.read_html(s, index_col=0)
|
2488 | 2487 |
|
@@ -2535,7 +2534,7 @@ in the method ``to_string`` described above.
|
2535 | 2534 |
|
2536 | 2535 | .. ipython:: python
|
2537 | 2536 |
|
2538 |
| - df = pd.DataFrame(randn(2, 2)) |
| 2537 | + df = pd.DataFrame(np.random.randn(2, 2)) |
2539 | 2538 | df
|
2540 | 2539 | print(df.to_html()) # raw html
|
2541 | 2540 |
|
@@ -2611,7 +2610,7 @@ Finally, the ``escape`` argument allows you to control whether the
|
2611 | 2610 |
|
2612 | 2611 | .. ipython:: python
|
2613 | 2612 |
|
2614 |
| - df = pd.DataFrame({'a': list('&<>'), 'b': randn(3)}) |
| 2613 | + df = pd.DataFrame({'a': list('&<>'), 'b': np.random.randn(3)}) |
2615 | 2614 |
|
2616 | 2615 |
|
2617 | 2616 | .. ipython:: python
|
@@ -3187,7 +3186,7 @@ applications (CTRL-V on many operating systems). Here we illustrate writing a
|
3187 | 3186 |
|
3188 | 3187 | .. ipython:: python
|
3189 | 3188 |
|
3190 |
| - df = pd.DataFrame(randn(5, 3)) |
| 3189 | + df = pd.DataFrame(np.random.randn(5, 3)) |
3191 | 3190 | df
|
3192 | 3191 | df.to_clipboard()
|
3193 | 3192 | pd.read_clipboard()
|
@@ -3414,10 +3413,10 @@ dict:
|
3414 | 3413 | .. ipython:: python
|
3415 | 3414 |
|
3416 | 3415 | index = pd.date_range('1/1/2000', periods=8)
|
3417 |
| - s = pd.Series(randn(5), index=['a', 'b', 'c', 'd', 'e']) |
3418 |
| - df = pd.DataFrame(randn(8, 3), index=index, |
| 3416 | + s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e']) |
| 3417 | + df = pd.DataFrame(np.random.randn(8, 3), index=index, |
3419 | 3418 | columns=['A', 'B', 'C'])
|
3420 |
| - wp = pd.Panel(randn(2, 5, 4), items=['Item1', 'Item2'], |
| 3419 | + wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'], |
3421 | 3420 | major_axis=pd.date_range('1/1/2000', periods=5),
|
3422 | 3421 | minor_axis=['A', 'B', 'C', 'D'])
|
3423 | 3422 |
|
@@ -3563,7 +3562,7 @@ This format is specified by default when using ``put`` or ``to_hdf`` or by ``for
|
3563 | 3562 |
|
3564 | 3563 | .. code-block:: python
|
3565 | 3564 |
|
3566 |
| - >>> pd.DataFrame(randn(10, 2)).to_hdf('test_fixed.h5', 'df') |
| 3565 | + >>> pd.DataFrame(np.random.randn(10, 2)).to_hdf('test_fixed.h5', 'df') |
3567 | 3566 | >>> pd.read_hdf('test_fixed.h5', 'df', where='index>5')
|
3568 | 3567 | TypeError: cannot pass a where specification when reading a fixed format.
|
3569 | 3568 | this store must be selected in its entirety
|
@@ -3699,9 +3698,9 @@ defaults to `nan`.
|
3699 | 3698 |
|
3700 | 3699 | .. ipython:: python
|
3701 | 3700 |
|
3702 |
| - df_mixed = pd.DataFrame({'A': randn(8), |
3703 |
| - 'B': randn(8), |
3704 |
| - 'C': np.array(randn(8), dtype='float32'), |
| 3701 | + df_mixed = pd.DataFrame({'A': np.random.randn(8), |
| 3702 | + 'B': np.random.randn(8), |
| 3703 | + 'C': np.array(np.random.randn(8), dtype='float32'), |
3705 | 3704 | 'string': 'string',
|
3706 | 3705 | 'int': 1,
|
3707 | 3706 | 'bool': True,
|
@@ -3841,7 +3840,7 @@ Here are some examples:
|
3841 | 3840 |
|
3842 | 3841 | .. ipython:: python
|
3843 | 3842 |
|
3844 |
| - dfq = pd.DataFrame(randn(10, 4), columns=list('ABCD'), |
| 3843 | + dfq = pd.DataFrame(np.random.randn(10, 4), columns=list('ABCD'), |
3845 | 3844 | index=pd.date_range('20130101', periods=10))
|
3846 | 3845 | store.append('dfq', dfq, format='table', data_columns=True)
|
3847 | 3846 |
|
@@ -3946,8 +3945,8 @@ Oftentimes when appending large amounts of data to a store, it is useful to turn
|
3946 | 3945 |
|
3947 | 3946 | .. ipython:: python
|
3948 | 3947 |
|
3949 |
| - df_1 = pd.DataFrame(randn(10, 2), columns=list('AB')) |
3950 |
| - df_2 = pd.DataFrame(randn(10, 2), columns=list('AB')) |
| 3948 | + df_1 = pd.DataFrame(np.random.randn(10, 2), columns=list('AB')) |
| 3949 | + df_2 = pd.DataFrame(np.random.randn(10, 2), columns=list('AB')) |
3951 | 3950 |
|
3952 | 3951 | st = pd.HDFStore('appends.h5', mode='w')
|
3953 | 3952 | st.append('df', df_1, data_columns=['B'], index=False)
|
@@ -4151,7 +4150,8 @@ results.
|
4151 | 4150 |
|
4152 | 4151 | .. ipython:: python
|
4153 | 4152 |
|
4154 |
| - df_mt = pd.DataFrame(randn(8, 6), index=pd.date_range('1/1/2000', periods=8), |
| 4153 | + df_mt = pd.DataFrame(np.random.randn(8, 6), |
| 4154 | + index=pd.date_range('1/1/2000', periods=8), |
4155 | 4155 | columns=['A', 'B', 'C', 'D', 'E', 'F'])
|
4156 | 4156 | df_mt['foo'] = 'bar'
|
4157 | 4157 | df_mt.loc[df_mt.index[1], ('A', 'B')] = np.nan
|
@@ -5181,7 +5181,7 @@ into a .dta file. The format version of this file is always 115 (Stata 12).
|
5181 | 5181 |
|
5182 | 5182 | .. ipython:: python
|
5183 | 5183 |
|
5184 |
| - df = pd.DataFrame(randn(10, 2), columns=list('AB')) |
| 5184 | + df = pd.DataFrame(np.random.randn(10, 2), columns=list('AB')) |
5185 | 5185 | df.to_stata('stata.dta')
|
5186 | 5186 |
|
5187 | 5187 | *Stata* data files have limited data type support; only strings with
|
@@ -5405,7 +5405,7 @@ ignored.
|
5405 | 5405 | .. code-block:: ipython
|
5406 | 5406 |
|
5407 | 5407 | In [1]: sz = 1000000
|
5408 |
| - In [2]: df = pd.DataFrame({'A': randn(sz), 'B': [1] * sz}) |
| 5408 | + In [2]: df = pd.DataFrame({'A': np.random.randn(sz), 'B': [1] * sz}) |
5409 | 5409 |
|
5410 | 5410 | In [3]: df.info()
|
5411 | 5411 | <class 'pandas.core.frame.DataFrame'>
|
|
0 commit comments