<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
import numpy as np

df = pd.DataFrame({ 'A' : 1.,
'B' : [2, 2, 4, 4],
'C' : ['T1', 'T2', 'T1', 'T2'],
'D' : 3.,
'E' : np.nan})
#df

tablea = pd.pivot_table(df, values='D', index=['A', 'B'],
                     columns=['C'], aggfunc=np.sum)
#tablea

tableb = pd.pivot_table(df, values='D', index=['E', 'B'],
                     columns=['C'], aggfunc=np.sum)
#tableb"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({ <span class="pl-s">'A'</span> : <span class="pl-c1">1.</span>,
<span class="pl-s">'B'</span> : [<span class="pl-c1">2</span>, <span class="pl-c1">2</span>, <span class="pl-c1">4</span>, <span class="pl-c1">4</span>],
<span class="pl-s">'C'</span> : [<span class="pl-s">'T1'</span>, <span class="pl-s">'T2'</span>, <span class="pl-s">'T1'</span>, <span class="pl-s">'T2'</span>],
<span class="pl-s">'D'</span> : <span class="pl-c1">3.</span>,
<span class="pl-s">'E'</span> : <span class="pl-s1">np</span>.<span class="pl-s1">nan</span>})
<span class="pl-c">#df</span>

<span class="pl-s1">tablea</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">pivot_table</span>(<span class="pl-s1">df</span>, <span class="pl-s1">values</span><span class="pl-c1">=</span><span class="pl-s">'D'</span>, <span class="pl-s1">index</span><span class="pl-c1">=</span>[<span class="pl-s">'A'</span>, <span class="pl-s">'B'</span>],
                     <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'C'</span>], <span class="pl-s1">aggfunc</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">sum</span>)
<span class="pl-c">#tablea</span>

<span class="pl-s1">tableb</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">pivot_table</span>(<span class="pl-s1">df</span>, <span class="pl-s1">values</span><span class="pl-c1">=</span><span class="pl-s">'D'</span>, <span class="pl-s1">index</span><span class="pl-c1">=</span>[<span class="pl-s">'E'</span>, <span class="pl-s">'B'</span>],
                     <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'C'</span>], <span class="pl-s1">aggfunc</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">sum</span>)
<span class="pl-c">#tableb</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">One is not able to use np.nan as a pivot value.</p>
<p dir="auto">The ouput for the first pivot table (tablea) as expected is</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="	C	T1	T2
A	B		
1.0	2	3.0	3.0
        4	3.0	3.0"><pre class="notranslate"><code class="notranslate">	C	T1	T2
A	B		
1.0	2	3.0	3.0
        4	3.0	3.0
</code></pre></div>
<p dir="auto">The output for the second table (tableb) is which is completely blank.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="E | B
-- | --"><pre class="notranslate"><code class="notranslate">E | B
-- | --
</code></pre></div>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">I was hoping for</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="	        C	T1	T2
E	        B		
np.nan	       2      	3.0	3.0
                4	3.0	3.0"><pre class="notranslate"><code class="notranslate">	        C	T1	T2
E	        B		
np.nan	       2      	3.0	3.0
                4	3.0	3.0
</code></pre></div>
<p dir="auto">This behavior is not necessarily a problem but I'm just trying to get clarity on if this is expected.<br>
I know that <code class="notranslate">groupby</code> excludes <code class="notranslate">NaN</code> by design and I expect that this is related to that. Is that the case?</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
<p dir="auto">pandas: 0.20.3<br>
pytest: 3.2.2<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.26.1<br>
numpy: 1.13.1<br>
scipy: 0.19.1<br>
xarray: None<br>
IPython: 6.1.0<br>
sphinx: 1.3.1<br>
patsy: 0.4.1<br>
dateutil: 2.6.1<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: 1.2.1<br>
tables: 3.4.2<br>
numexpr: 2.6.2<br>
feather: 0.4.0<br>
matplotlib: 2.0.2<br>
openpyxl: 2.5.0a3<br>
xlrd: 1.0.0<br>
xlwt: 1.2.0<br>
xlsxwriter: 0.9.8<br>
lxml: 3.8.0<br>
bs4: 4.6.0<br>
html5lib: 0.999999999<br>
sqlalchemy: 1.1.11<br>
pymysql: 0.7.9.None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">ENH: maybe for now just provide a warning if dropping the nan rows when pivotting...</p>
<p dir="auto">rom ml</p>
<p dir="auto"><a href="http://stackoverflow.com/questions/16860172/python-pandas-pivot-table-silently-drops-indices-with-nans" rel="nofollow">http://stackoverflow.com/questions/16860172/python-pandas-pivot-table-silently-drops-indices-with-nans</a></p>
<p dir="auto">This is effectivly trying to groupby on a NaN, currently not allowed</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [13]: a = [['a', 'b', 12, 12, 12], ['a', nan, 12.3, 233., 12], ['b', 'a', 123.23, 123, 1], ['a', 'b', 1, 1, 1.]]

In [14]: df = DataFrame(a, columns=['a', 'b', 'c', 'd', 'e'])

In [15]: df.groupby(['a','b']).sum()
Out[15]: 
          c    d   e
a b                 
a b   13.00   13  13
b a  123.23  123   1"><pre class="notranslate"><code class="notranslate">In [13]: a = [['a', 'b', 12, 12, 12], ['a', nan, 12.3, 233., 12], ['b', 'a', 123.23, 123, 1], ['a', 'b', 1, 1, 1.]]

In [14]: df = DataFrame(a, columns=['a', 'b', 'c', 'd', 'e'])

In [15]: df.groupby(['a','b']).sum()
Out[15]: 
          c    d   e
a b                 
a b   13.00   13  13
b a  123.23  123   1
</code></pre></div>
<p dir="auto">Workaround to fill the index with a dummy, pivot, and replace</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
    In [31]: df2 = df.copy()

    In [32]: df2['dummy'] = np.nan

    In [33]: df2['b'] = df2['b'].fillna('dummy')

    In [34]: df2
    Out[34]: 
       a      b       c    d   e  dummy
    0  a      b   12.00   12  12    NaN
    1  a  dummy   12.30  233  12    NaN
    2  b      a  123.23  123   1    NaN
    3  a      b    1.00    1   1    NaN

    In [35]: df2.pivot_table(rows=['a', 'b'], values=['c', 'd', 'e'], aggfunc=sum)
    Out[35]: 
       a      b       c    d   e
    0  a      b   13.00   13  13
    1  a  dummy   12.30  233  12
    2  b      a  123.23  123   1

    In [36]: df2.pivot_table(rows=['a', 'b'], values=['c', 'd', 'e'], aggfunc=sum).replace('dummy',np.nan)
    Out[36]: 
       a    b       c    d   e
    0  a    b   13.00   13  13
    1  a  NaN   12.30  233  12
    2  b    a  123.23  123   1
"><pre class="notranslate"><code class="notranslate">
    In [31]: df2 = df.copy()

    In [32]: df2['dummy'] = np.nan

    In [33]: df2['b'] = df2['b'].fillna('dummy')

    In [34]: df2
    Out[34]: 
       a      b       c    d   e  dummy
    0  a      b   12.00   12  12    NaN
    1  a  dummy   12.30  233  12    NaN
    2  b      a  123.23  123   1    NaN
    3  a      b    1.00    1   1    NaN

    In [35]: df2.pivot_table(rows=['a', 'b'], values=['c', 'd', 'e'], aggfunc=sum)
    Out[35]: 
       a      b       c    d   e
    0  a      b   13.00   13  13
    1  a  dummy   12.30  233  12
    2  b      a  123.23  123   1

    In [36]: df2.pivot_table(rows=['a', 'b'], values=['c', 'd', 'e'], aggfunc=sum).replace('dummy',np.nan)
    Out[36]: 
       a    b       c    d   e
    0  a    b   13.00   13  13
    1  a  NaN   12.30  233  12
    2  b    a  123.23  123   1

</code></pre></div>