Skip to content

Commit 3f48918

Browse files
Merge remote-tracking branch 'upstream/master' into DOC_series_idxmax
2 parents 8c5d0a6 + d7bcb22 commit 3f48918

File tree

2 files changed

+83
-7
lines changed

2 files changed

+83
-7
lines changed

pandas/core/generic.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4166,7 +4166,55 @@ def as_matrix(self, columns=None):
41664166

41674167
@property
41684168
def values(self):
4169-
"""Numpy representation of NDFrame
4169+
"""
4170+
Return a Numpy representation of the DataFrame.
4171+
4172+
Only the values in the DataFrame will be returned, the axes labels
4173+
will be removed.
4174+
4175+
Returns
4176+
-------
4177+
numpy.ndarray
4178+
The values of the DataFrame.
4179+
4180+
Examples
4181+
--------
4182+
A DataFrame where all columns are the same type (e.g., int64) results
4183+
in an array of the same type.
4184+
4185+
>>> df = pd.DataFrame({'age': [ 3, 29],
4186+
... 'height': [94, 170],
4187+
... 'weight': [31, 115]})
4188+
>>> df
4189+
age height weight
4190+
0 3 94 31
4191+
1 29 170 115
4192+
>>> df.dtypes
4193+
age int64
4194+
height int64
4195+
weight int64
4196+
dtype: object
4197+
>>> df.values
4198+
array([[ 3, 94, 31],
4199+
[ 29, 170, 115]], dtype=int64)
4200+
4201+
A DataFrame with mixed type columns(e.g., str/object, int64, float32)
4202+
results in an ndarray of the broadest type that accommodates these
4203+
mixed types (e.g., object).
4204+
4205+
>>> df2 = pd.DataFrame([('parrot', 24.0, 'second'),
4206+
... ('lion', 80.5, 1),
4207+
... ('monkey', np.nan, None)],
4208+
... columns=('name', 'max_speed', 'rank'))
4209+
>>> df2.dtypes
4210+
name object
4211+
max_speed float64
4212+
rank object
4213+
dtype: object
4214+
>>> df2.values
4215+
array([['parrot', 24.0, 'second'],
4216+
['lion', 80.5, 1],
4217+
['monkey', nan, None]], dtype=object)
41704218
41714219
Notes
41724220
-----
@@ -4177,8 +4225,13 @@ def values(self):
41774225
41784226
e.g. If the dtypes are float16 and float32, dtype will be upcast to
41794227
float32. If dtypes are int32 and uint8, dtype will be upcast to
4180-
int32. By numpy.find_common_type convention, mixing int64 and uint64
4181-
will result in a flot64 dtype.
4228+
int32. By :func:`numpy.find_common_type` convention, mixing int64
4229+
and uint64 will result in a float64 dtype.
4230+
4231+
See Also
4232+
--------
4233+
pandas.DataFrame.index : Retrievie the index labels
4234+
pandas.DataFrame.columns : Retrieving the column names
41824235
"""
41834236
self._consolidate_inplace()
41844237
return self._data.as_array(transpose=self._AXIS_REVERSED)

pandas/core/indexes/multi.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,22 +1775,45 @@ def droplevel(self, level=0):
17751775

17761776
def swaplevel(self, i=-2, j=-1):
17771777
"""
1778-
Swap level i with level j. Do not change the ordering of anything
1778+
Swap level i with level j.
1779+
1780+
Calling this method does not change the ordering of the values.
17791781
17801782
Parameters
17811783
----------
1782-
i, j : int, string (can be mixed)
1783-
Level of index to be swapped. Can pass level name as string.
1784+
i : int, str, default -2
1785+
First level of index to be swapped. Can pass level name as string.
1786+
Type of parameters can be mixed.
1787+
j : int, str, default -1
1788+
Second level of index to be swapped. Can pass level name as string.
1789+
Type of parameters can be mixed.
17841790
17851791
Returns
17861792
-------
1787-
swapped : MultiIndex
1793+
MultiIndex
1794+
A new MultiIndex
17881795
17891796
.. versionchanged:: 0.18.1
17901797
17911798
The indexes ``i`` and ``j`` are now optional, and default to
17921799
the two innermost levels of the index.
17931800
1801+
See Also
1802+
--------
1803+
Series.swaplevel : Swap levels i and j in a MultiIndex
1804+
Dataframe.swaplevel : Swap levels i and j in a MultiIndex on a
1805+
particular axis
1806+
1807+
Examples
1808+
--------
1809+
>>> mi = pd.MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1810+
... labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1811+
>>> mi
1812+
MultiIndex(levels=[['a', 'b'], ['bb', 'aa']],
1813+
labels=[[0, 0, 1, 1], [0, 1, 0, 1]])
1814+
>>> mi.swaplevel(0, 1)
1815+
MultiIndex(levels=[['bb', 'aa'], ['a', 'b']],
1816+
labels=[[0, 1, 0, 1], [0, 0, 1, 1]])
17941817
"""
17951818
new_levels = list(self.levels)
17961819
new_labels = list(self.labels)

0 commit comments

Comments
 (0)