Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: resolved mistakes in examples series #15625

Merged
merged 3 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ def swaplevel(self, i=-2, j=-1, axis=0):
dtype: int64
>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
>>> df.rename(2)
Traceback (most recent call last):
...
TypeError: 'int' object is not callable
>>> df.rename(index=str, columns={"A": "a", "B": "c"})
Expand Down Expand Up @@ -1115,7 +1116,7 @@ def __setstate__(self, state):
to the existing workbook. This can be used to save different
DataFrames to one workbook:

>>> writer = ExcelWriter('output.xlsx')
>>> writer = pd.ExcelWriter('output.xlsx')
>>> df1.to_excel(writer,'Sheet1')
>>> df2.to_excel(writer,'Sheet2')
>>> writer.save()
Expand Down Expand Up @@ -2260,7 +2261,7 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
... 'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]},
... index=index)
>>> df
http_status response_time
http_status response_time
Firefox 200 0.04
Chrome 200 0.02
Safari 404 0.07
Expand All @@ -2275,11 +2276,11 @@ def sort_index(self, axis=0, level=None, ascending=True, inplace=False,
... 'Chrome']
>>> df.reindex(new_index)
http_status response_time
Safari 404 0.07
Safari 404.0 0.07
Iceweasel NaN NaN
Comodo Dragon NaN NaN
IE10 404 0.08
Chrome 200 0.02
IE10 404.0 0.08
Chrome 200.0 0.02

We can fill in the missing values by passing a value to
the keyword ``fill_value``. Because the index is not monotonically
Expand Down
71 changes: 50 additions & 21 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ def values(self):
Timezone aware datetime data is converted to UTC:

>>> pd.Series(pd.date_range('20130101', periods=3,
tz='US/Eastern')).values
array(['2013-01-01T00:00:00.000000000-0500',
'2013-01-02T00:00:00.000000000-0500',
'2013-01-03T00:00:00.000000000-0500'], dtype='datetime64[ns]')
... tz='US/Eastern')).values
array(['2013-01-01T05:00:00.000000000',
'2013-01-02T05:00:00.000000000',
'2013-01-03T05:00:00.000000000'], dtype='datetime64[ns]')

"""
return self._data.external_values()
Expand Down Expand Up @@ -1550,6 +1550,8 @@ def append(self, to_append, ignore_index=False, verify_integrity=False):
With `verify_integrity` set to True:

>>> s1.append(s2, verify_integrity=True)
Traceback (most recent call last):
...
ValueError: Indexes have overlapping values: [0, 1, 2]


Expand Down Expand Up @@ -1919,8 +1921,19 @@ def nlargest(self, n=5, keep='first'):
--------
>>> import pandas as pd
>>> import numpy as np
>>> s = pd.Series(np.random.randn(1e6))
>>> s = pd.Series(np.random.randn(10**6))
>>> s.nlargest(10) # only sorts up to the N requested
219921 4.644710
82124 4.608745
421689 4.564644
425277 4.447014
718691 4.414137
43154 4.403520
283187 4.313922
595519 4.273635
503969 4.250236
121637 4.240952
dtype: float64
"""
return algorithms.select_n_series(self, n=n, keep=keep,
method='nlargest')
Expand Down Expand Up @@ -1958,8 +1971,19 @@ def nsmallest(self, n=5, keep='first'):
--------
>>> import pandas as pd
>>> import numpy as np
>>> s = pd.Series(np.random.randn(1e6))
>>> s = pd.Series(np.random.randn(10**6))
>>> s.nsmallest(10) # only sorts up to the N requested
288532 -4.954580
732345 -4.835960
64803 -4.812550
446457 -4.609998
501225 -4.483945
669476 -4.472935
973615 -4.401699
621279 -4.355126
773916 -4.347355
359919 -4.331927
dtype: float64
"""
return algorithms.select_n_series(self, n=n, keep=keep,
method='nsmallest')
Expand Down Expand Up @@ -2052,21 +2076,24 @@ def unstack(self, level=-1, fill_value=None):

Examples
--------
>>> s = pd.Series([1, 2, 3, 4],
... index=pd.MultiIndex.from_product([['one', 'two'], ['a', 'b']]))
>>> s
one a 1.
one b 2.
two a 3.
two b 4.
one a 1
b 2
two a 3
b 4
dtype: int64

>>> s.unstack(level=-1)
a b
one 1. 2.
two 3. 4.
a b
one 1 2
two 3 4

>>> s.unstack(level=0)
one two
a 1. 2.
b 3. 4.
a 1 3
b 2 4

Returns
-------
Expand Down Expand Up @@ -2102,15 +2129,16 @@ def map(self, arg, na_action=None):

>>> x = pd.Series([1,2,3], index=['one', 'two', 'three'])
>>> x
one 1
two 2
three 3
one 1
two 2
three 3
dtype: int64

>>> y = pd.Series(['foo', 'bar', 'baz'], index=[1,2,3])
>>> y
1 foo
2 bar
3 baz
1 foo
2 bar
3 baz

>>> x.map(y)
one foo
Expand Down Expand Up @@ -2215,6 +2243,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):
>>> import numpy as np
>>> series = pd.Series([20, 21, 12], index=['London',
... 'New York','Helsinki'])
>>> series
London 20
New York 21
Helsinki 12
Expand Down