Skip to content

Commit d464f75

Browse files
author
Chang She
committed
DOC: additional linking from whatsnew and added examples for various features
1 parent b874d83 commit d464f75

File tree

5 files changed

+106
-5
lines changed

5 files changed

+106
-5
lines changed

doc/source/io.rst

+22
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,28 @@ a single date rather than the entire array.
296296
297297
os.remove('tmp.csv')
298298
299+
.. _io.dayfirst:
300+
301+
International Date Formats
302+
~~~~~~~~~~~~~~~~~~~~~~~~~~
303+
While US date formats tend to be MM/DD/YYYY, many international formats use
304+
DD/MM/YYYY instead. For convenience, a ``dayfirst`` keyword is provided:
305+
306+
.. ipython:: python
307+
:suppress:
308+
309+
data = "date,value,cat\n1/6/2000,5,a\n2/6/2000,10,b\n3/6/2000,15,c"
310+
with open('tmp.csv', 'w') as fh:
311+
fh.write(data)
312+
313+
.. ipython:: python
314+
315+
print open('tmp.csv').read()
316+
317+
read_csv('tmp.csv', parse_dates=[0])
318+
319+
read_csv('tmp.csv', dayfirst=True, parse_dates=[0])
320+
299321
.. _io.thousands:
300322

301323
Thousand Separators

doc/source/merging.rst

+27
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,32 @@ columns:
537537
``DataFrame.join`` has ``lsuffix`` and ``rsuffix`` arguments which behave
538538
similarly.
539539

540+
.. _merging.ordered_merge:
541+
542+
Merging Ordered Data
543+
~~~~~~~~~~~~~~~~~~~~
544+
545+
New in v0.8.0 is the ordered_merge function for combining time series and other
546+
ordered data. In particular it has an optional ``fill_method`` keyword to
547+
fill/interpolate missing data:
548+
549+
.. ipython:: python
550+
:suppress:
551+
552+
A = DataFrame({'key' : ['a', 'c', 'e'] * 2,
553+
'lvalue' : [1, 2, 3] * 2,
554+
'group' : ['a', 'a', 'a', 'b', 'b', 'b']})
555+
B = DataFrame({'key' : ['b', 'c', 'd'],
556+
'rvalue' : [1, 2, 3]})
557+
558+
.. ipython:: python
559+
560+
A
561+
562+
B
563+
564+
ordered_merge(A, B, fill_method='ffill', left_by='group')
565+
540566
.. _merging.multiple_join:
541567

542568
Joining multiple DataFrame or Panel objects
@@ -575,6 +601,7 @@ For this, use the ``combine_first`` method:
575601
576602
df1.combine_first(df2)
577603
604+
.. _merging.combine_first.update:
578605
Note that this method only takes values from the right DataFrame if they are
579606
missing in the left DataFrame. A related method, ``update``, alters non-NA
580607
values inplace:

doc/source/missing_data.rst

+45
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,51 @@ for interpolation methods outside of the filling methods described above.
237237
238238
plt.close('all')
239239
240+
.. _missing_data.replace:
241+
242+
Replacing Generic Values
243+
~~~~~~~~~~~~~~~~~~~~~~~~
244+
Often times we want to replace arbitrary values with other values. New in v0.8
245+
is the ``replace`` method in Series/DataFrame that provides an efficient yet
246+
flexible way to perform such replacements.
247+
248+
For a Series, you can replace a single value or a list of values by another
249+
value:
250+
251+
.. ipython:: python
252+
253+
ser = Series([0., 1., 2., 3., 4.])
254+
255+
ser.replace(0, 5)
256+
257+
You can replace a list of values by a list of other values:
258+
259+
.. ipython:: python
260+
261+
ser.replace([0, 1, 2, 3, 4], [4, 3, 2, 1, 0])
262+
263+
You can also specify a mapping dict:
264+
265+
.. ipython:: python
266+
267+
ser.replace({0: 10, 1: 100})
268+
269+
For a DataFrame, you can specify individual values by column:
270+
271+
.. ipython:: python
272+
273+
df = DataFrame({'a': [0, 1, 2, 3, 4], 'b': [5, 6, 7, 8, 9]})
274+
275+
df.replace({'a': 0, 'b': 5}, 100)
276+
277+
Instead of replacing with specified values, you can treat all given values as
278+
missing and interpolate over them:
279+
280+
.. ipython:: python
281+
282+
ser.replace([1, 2, 3], method='pad')
283+
284+
240285
Missing data casting rules and indexing
241286
---------------------------------------
242287

doc/source/visualization.rst

+5
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ Scatter plot matrix
249249
*New in 0.8.0* You can create density plots using the Series/DataFrame.plot and
250250
setting `kind='kde'`:
251251

252+
.. ipython:: python
253+
:suppress:
254+
255+
plt.figure();
256+
252257
.. ipython:: python
253258
254259
ser = Series(np.random.randn(1000))

doc/source/whatsnew/v0.8.0.txt

+7-5
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ Other new features
110110
- Add :ref:`limit <missing_data.fillna.limit>` argument to fillna/reindex
111111
- More flexible multiple function application in GroupBy, and can pass list
112112
(name, function) tuples to get result in particular order with given names
113-
- Add flexible ``replace`` method for efficiently substituting values
113+
- Add flexible :ref:`replace <missing_data.replace>` method for efficiently
114+
substituting values
114115
- Enhanced :ref:`read_csv/read_table <io.parse_dates>` for reading time series
115116
data and converting multiple columns to dates
116117
- Add :ref:`comments <io.comments>` option to parser functions: read_csv, etc.
117-
- Add ``dayfirst`` option to parser functions for parsing international
118-
DD/MM/YYYY dates
118+
- Add :ref`dayfirst <io.dayfirst>` option to parser functions for parsing
119+
international DD/MM/YYYY dates
119120
- Allow the user to specify the CSV reader :ref:`dialect <io.dialect>` to
120121
control quoting etc.
121122
- Handling :ref:`thousands <io.thousands>` separators in read_csv to improve
@@ -125,7 +126,7 @@ Other new features
125126
- Move to klib-based hash tables for indexing; better performance and less
126127
memory usage than Python's dict
127128
- Add first, last, min, max, and prod optimized GroupBy functions
128-
- New ordered_merge function
129+
- New :ref:`ordered_merge <merging.ordered_merge>` function
129130
- Add flexible comparison instance methods eq, ne, lt, gt, etc. to DataFrame,
130131
Series
131132
- Improve :ref:`scatter_matrix <visualization.scatter_matrix>` plotting
@@ -137,7 +138,8 @@ Other new features
137138
- Add max_colwidth configuration option for DataFrame console output
138139
- Interpolate Series values using index values
139140
- Can select multiple columns from GroupBy
140-
- Add Series/DataFrame.:ref:`update <merging.combine_first.update>` methods for updating values in place
141+
- Add :ref:`update <merging.combine_first.update>` methods to Series/DataFrame
142+
for updating values in place
141143

142144
Other API changes
143145
~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)