Skip to content

Commit 2e18d1a

Browse files
Merge pull request #6746 from jorisvandenbossche/doc-fixes
Doc fixes
2 parents c2b8c45 + 40045dc commit 2e18d1a

File tree

4 files changed

+59
-23
lines changed

4 files changed

+59
-23
lines changed

doc/source/io.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1878,14 +1878,14 @@ to be parsed.
18781878

18791879
.. code-block:: python
18801880
1881-
read_excel('path_to_file.xls', 'Sheet1', parse_cols=2, index_col=None, na_values=['NA'])
1881+
read_excel('path_to_file.xls', 'Sheet1', parse_cols=2)
18821882
18831883
If `parse_cols` is a list of integers, then it is assumed to be the file column
18841884
indices to be parsed.
18851885

18861886
.. code-block:: python
18871887
1888-
read_excel('path_to_file.xls', 'Sheet1', parse_cols=[0, 2, 3], index_col=None, na_values=['NA'])
1888+
read_excel('path_to_file.xls', 'Sheet1', parse_cols=[0, 2, 3])
18891889
18901890
To write a DataFrame object to a sheet of an Excel file, you can use the
18911891
``to_excel`` instance method. The arguments are largely the same as ``to_csv``

doc/source/reshaping.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ the right thing:
199199
Reshaping by Melt
200200
-----------------
201201

202-
The ``melt`` function found in ``pandas.core.reshape`` is useful to massage a
202+
The :func:`~pandas.melt` function is useful to massage a
203203
DataFrame into a format where one or more columns are identifier variables,
204-
while all other columns, considered measured variables, are "pivoted" to the
204+
while all other columns, considered measured variables, are "unpivoted" to the
205205
row axis, leaving just two non-identifier columns, "variable" and "value". The
206206
names of those columns can be customized by supplying the ``var_name`` and
207207
``value_name`` parameters.

doc/source/visualization.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ bar plot:
261261
.. ipython:: python
262262
:suppress:
263263
264-
plt.figure();
264+
plt.figure()
265265
266266
.. ipython:: python
267267
@@ -275,7 +275,7 @@ To produce a stacked bar plot, pass ``stacked=True``:
275275
.. ipython:: python
276276
:suppress:
277277
278-
plt.figure();
278+
plt.figure()
279279
280280
.. ipython:: python
281281
@@ -287,7 +287,7 @@ To get horizontal bar plots, pass ``kind='barh'``:
287287
.. ipython:: python
288288
:suppress:
289289
290-
plt.figure();
290+
plt.figure()
291291
292292
.. ipython:: python
293293
@@ -320,7 +320,7 @@ New since 0.10.0, the ``by`` keyword can be specified to plot grouped histograms
320320
.. ipython:: python
321321
:suppress:
322322
323-
plt.figure();
323+
plt.figure()
324324
325325
.. ipython:: python
326326
@@ -434,12 +434,12 @@ Scatter plot matrix
434434
.. _visualization.kde:
435435

436436
*New in 0.8.0* You can create density plots using the Series/DataFrame.plot and
437-
setting `kind='kde'`:
437+
setting ``kind='kde'``:
438438

439439
.. ipython:: python
440440
:suppress:
441441
442-
plt.figure();
442+
plt.figure()
443443
444444
.. ipython:: python
445445
@@ -460,7 +460,7 @@ too dense to plot each point individually.
460460
.. ipython:: python
461461
:suppress:
462462
463-
plt.figure();
463+
plt.figure()
464464
465465
.. ipython:: python
466466
@@ -486,7 +486,7 @@ given by column ``z``. The bins are aggregated with numpy's ``max`` function.
486486
.. ipython:: python
487487
:suppress:
488488
489-
plt.figure();
489+
plt.figure()
490490
491491
.. ipython:: python
492492

pandas/core/reshape.py

+47-11
Original file line numberDiff line numberDiff line change
@@ -617,52 +617,88 @@ def melt(frame, id_vars=None, value_vars=None,
617617
var_name=None, value_name='value', col_level=None):
618618
"""
619619
"Unpivots" a DataFrame from wide format to long format, optionally leaving
620-
id variables set
620+
identifier variables set.
621+
622+
This function is useful to massage a DataFrame into a format where one
623+
or more columns are identifier variables (`id_vars`), while all other
624+
columns, considered measured variables (`value_vars`), are "unpivoted" to
625+
the row axis, leaving just two non-identifier columns, 'variable' and
626+
'value'.
621627
622628
Parameters
623629
----------
624630
frame : DataFrame
625-
id_vars : tuple, list, or ndarray
626-
value_vars : tuple, list, or ndarray
627-
var_name : scalar, if None uses frame.column.name or 'variable'
631+
id_vars : tuple, list, or ndarray, optional
632+
Column(s) to use as identifier variables.
633+
value_vars : tuple, list, or ndarray, optional
634+
Column(s) to unpivot. If not specified, uses all columns that
635+
are not set as `id_vars`.
636+
var_name : scalar
637+
Name to use for the 'variable' column. If None it uses
638+
``frame.columns.name`` or 'variable'.
628639
value_name : scalar, default 'value'
629-
col_level : scalar, if columns are a MultiIndex then use this level to melt
640+
Name to use for the 'value' column.
641+
col_level : int or string, optional
642+
If columns are a MultiIndex then use this level to melt.
643+
644+
See also
645+
--------
646+
pivot_table
647+
DataFrame.pivot
630648
631649
Examples
632650
--------
633651
>>> import pandas as pd
634652
>>> df = pd.DataFrame({'A': {0: 'a', 1: 'b', 2: 'c'},
635653
... 'B': {0: 1, 1: 3, 2: 5},
636654
... 'C': {0: 2, 1: 4, 2: 6}})
637-
638655
>>> df
639656
A B C
640657
0 a 1 2
641658
1 b 3 4
642659
2 c 5 6
643660
644-
>>> melt(df, id_vars=['A'], value_vars=['B'])
661+
>>> pd.melt(df, id_vars=['A'], value_vars=['B'])
662+
A variable value
663+
0 a B 1
664+
1 b B 3
665+
2 c B 5
666+
667+
>>> pd.melt(df, id_vars=['A'], value_vars=['B', 'C'])
645668
A variable value
646669
0 a B 1
647670
1 b B 3
648671
2 c B 5
672+
3 a C 2
673+
4 b C 4
674+
5 c C 6
675+
676+
The names of 'variable' and 'value' columns can be customized:
649677
650-
>>> melt(df, id_vars=['A'], value_vars=['B'],
651-
... var_name='myVarname', value_name='myValname')
678+
>>> pd.melt(df, id_vars=['A'], value_vars=['B'],
679+
... var_name='myVarname', value_name='myValname')
652680
A myVarname myValname
653681
0 a B 1
654682
1 b B 3
655683
2 c B 5
656684
685+
If you have multi-index columns:
686+
657687
>>> df.columns = [list('ABC'), list('DEF')]
688+
>>> df
689+
A B C
690+
D E F
691+
0 a 1 2
692+
1 b 3 4
693+
2 c 5 6
658694
659-
>>> melt(df, col_level=0, id_vars=['A'], value_vars=['B'])
695+
>>> pd.melt(df, col_level=0, id_vars=['A'], value_vars=['B'])
660696
A variable value
661697
0 a B 1
662698
1 b B 3
663699
2 c B 5
664700
665-
>>> melt(df, id_vars=[('A', 'D')], value_vars=[('B', 'E')])
701+
>>> pd.melt(df, id_vars=[('A', 'D')], value_vars=[('B', 'E')])
666702
(A, D) variable_0 variable_1 value
667703
0 a B E 1
668704
1 b B E 3

0 commit comments

Comments
 (0)