Skip to content

Commit 705b677

Browse files
committed
DOC: doc corrections basics.rst / io.rst
1 parent 6a54af8 commit 705b677

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

doc/source/basics.rst

+21-16
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,11 @@ Similarly, you can get the most frequently occuring value(s) (the mode) of the v
492492

493493
.. ipython:: python
494494
495-
data = [1, 1, 3, 3, 3, 5, 5, 7, 7, 7]
496-
s = Series(data)
497-
s.mode()
498-
df = pd.DataFrame({"A": np.random.randint(0, 7, size=50),
499-
"B": np.random.randint(-10, 15, size=50)})
500-
df.mode()
495+
s5 = Series([1, 1, 3, 3, 3, 5, 5, 7, 7, 7])
496+
s5.mode()
497+
df5 = DataFrame({"A": np.random.randint(0, 7, size=50),
498+
"B": np.random.randint(-10, 15, size=50)})
499+
df5.mode()
501500
502501
503502
Discretization and quantiling
@@ -613,11 +612,17 @@ another array or value), the methods ``applymap`` on DataFrame and analogously
613612
``map`` on Series accept any Python function taking a single value and
614613
returning a single value. For example:
615614

615+
.. ipython:: python
616+
:suppress:
617+
618+
df4 = df_orig.copy()
619+
616620
.. ipython:: python
617621
622+
df4
618623
f = lambda x: len(str(x))
619-
df['one'].map(f)
620-
df.applymap(f)
624+
df4['one'].map(f)
625+
df4.applymap(f)
621626
622627
``Series.map`` has an additional feature which is that it can be used to easily
623628
"link" or "map" values defined by a secondary series. This is closely related
@@ -712,13 +717,13 @@ make this simpler:
712717
:suppress:
713718
714719
df2 = df.reindex(['a', 'b', 'c'], columns=['one', 'two'])
715-
df2 = df2 - df2.mean()
720+
df3 = df2 - df2.mean()
716721
717722
718723
.. ipython:: python
719724
720-
df
721725
df2
726+
df3
722727
df.reindex_like(df2)
723728
724729
Reindexing with ``reindex_axis``
@@ -1010,7 +1015,7 @@ Extracting Substrings
10101015
~~~~~~~~~~~~~~~~~~~~~
10111016

10121017
The method ``extract`` (introduced in version 0.13) accepts regular expressions
1013-
with match groups. Extracting a regular expression with one group returns
1018+
with match groups. Extracting a regular expression with one group returns
10141019
a Series of strings.
10151020

10161021
.. ipython:: python
@@ -1043,7 +1048,7 @@ and optional groups like
10431048
10441049
can also be used.
10451050

1046-
Testing for Strings that Match or Contain a Pattern
1051+
Testing for Strings that Match or Contain a Pattern
10471052
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10481053

10491054
In previous versions, *extracting* match groups was accomplished by ``match``,
@@ -1055,8 +1060,8 @@ The distinction between
10551060
``match`` and ``contains`` is strictness: ``match`` relies on
10561061
strict ``re.match`` while ``contains`` relies on ``re.search``.
10571062

1058-
In version 0.13, ``match`` performs its old, deprecated behavior by default,
1059-
but the new behavior is availabe through the keyword argument
1063+
In version 0.13, ``match`` performs its old, deprecated behavior by default,
1064+
but the new behavior is availabe through the keyword argument
10601065
``as_indexer=True``.
10611066

10621067
Methods like ``match``, ``contains``, ``startswith``, and ``endswith`` take
@@ -1118,13 +1123,13 @@ determine the sort order:
11181123

11191124
.. ipython:: python
11201125
1121-
df.sort_index(by='two')
1126+
df1 = DataFrame({'one':[2,1,1,1],'two':[1,3,2,4],'three':[5,4,3,2]})
1127+
df1.sort_index(by='two')
11221128
11231129
The ``by`` argument can take a list of column names, e.g.:
11241130

11251131
.. ipython:: python
11261132
1127-
df1 = DataFrame({'one':[2,1,1,1],'two':[1,3,2,4],'three':[5,4,3,2]})
11281133
df1[['one', 'two', 'three']].sort_index(by=['one','two'])
11291134
11301135
Series has the method ``order`` (analogous to `R's order function

doc/source/io.rst

+15
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,21 @@ pandas objects.
20332033
os.remove('foo.msg')
20342034
os.remove('foo2.msg')
20352035
2036+
Read/Write API
2037+
~~~~~~~~~~~~~~
2038+
2039+
Msgpacks can also be read from and written to strings.
2040+
2041+
.. ipython:: python
2042+
2043+
df.to_msgpack()
2044+
2045+
Furthermore you can concatenate the strings to produce a list of the original objects.
2046+
2047+
.. ipython:: python
2048+
2049+
pd.read_msgpack(df.to_msgpack() + s.to_msgpack())
2050+
20362051
.. _io.hdf5:
20372052

20382053
HDF5 (PyTables)

0 commit comments

Comments
 (0)