<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="# categorical_DataFrame is constructed from a source table by appending transformed original data column-by-column using original_DataFrame[column_name].values
# The original dataframe has also undergone some operations after loading and before constructing the categorical_DataFrame: type conversion, value substitution, and re-indexing.
categorical_DataFrame = pd.DataFrame(index=origin_DataFrame['GID'])
for akey, avalue in column_translation_dict.items():
    if akey in origin_DataFrame.columns:
        categorical_DataFrame[avalue] = origin_DataFrame[akey].values
    else:
        print('Cannot find column ' + akey)

# trying to visualize
for column_name in categorical_DataFrame:
    if str(categorical_DataFrame[column_name].dtype) is 'category':
        count_Series = categorical_DataFrame[column_name].value_counts(dropna=False) # Same bug if dropna=True
        print(count_Series)  # This yields the correct result
        plt_ax = count_Series.plot.bar()  # This yields incorrect graph

# If save it to a new .csv file and reload, though:
categorical_DataFrame.to_csv('saved_table.csv')
new_DataFrame = pd.read_csv('saved_table.csv', index_cols='GID')
for column_name in new_DataFrame:
    if str(new_DataFrame[column_name].dtype) is 'category':
        count_Series = new_DataFrame[column_name].value_counts(dropna=False) # basically same operations
        print(count_Series)  # Still correct
        plt_ax = count_Series.plot.bar()  # This now yields correct graphs."><pre class="notranslate"><span class="pl-c"># categorical_DataFrame is constructed from a source table by appending transformed original data column-by-column using original_DataFrame[column_name].values</span>
<span class="pl-c"># The original dataframe has also undergone some operations after loading and before constructing the categorical_DataFrame: type conversion, value substitution, and re-indexing.</span>
<span class="pl-s1">categorical_DataFrame</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">origin_DataFrame</span>[<span class="pl-s">'GID'</span>])
<span class="pl-k">for</span> <span class="pl-s1">akey</span>, <span class="pl-s1">avalue</span> <span class="pl-c1">in</span> <span class="pl-s1">column_translation_dict</span>.<span class="pl-en">items</span>():
    <span class="pl-k">if</span> <span class="pl-s1">akey</span> <span class="pl-c1">in</span> <span class="pl-s1">origin_DataFrame</span>.<span class="pl-s1">columns</span>:
        <span class="pl-s1">categorical_DataFrame</span>[<span class="pl-s1">avalue</span>] <span class="pl-c1">=</span> <span class="pl-s1">origin_DataFrame</span>[<span class="pl-s1">akey</span>].<span class="pl-s1">values</span>
    <span class="pl-k">else</span>:
        <span class="pl-en">print</span>(<span class="pl-s">'Cannot find column '</span> <span class="pl-c1">+</span> <span class="pl-s1">akey</span>)

<span class="pl-c"># trying to visualize</span>
<span class="pl-k">for</span> <span class="pl-s1">column_name</span> <span class="pl-c1">in</span> <span class="pl-s1">categorical_DataFrame</span>:
    <span class="pl-k">if</span> <span class="pl-en">str</span>(<span class="pl-s1">categorical_DataFrame</span>[<span class="pl-s1">column_name</span>].<span class="pl-s1">dtype</span>) <span class="pl-c1">is</span> <span class="pl-s">'category'</span>:
        <span class="pl-s1">count_Series</span> <span class="pl-c1">=</span> <span class="pl-s1">categorical_DataFrame</span>[<span class="pl-s1">column_name</span>].<span class="pl-en">value_counts</span>(<span class="pl-s1">dropna</span><span class="pl-c1">=</span><span class="pl-c1">False</span>) <span class="pl-c"># Same bug if dropna=True</span>
        <span class="pl-en">print</span>(<span class="pl-s1">count_Series</span>)  <span class="pl-c"># This yields the correct result</span>
        <span class="pl-s1">plt_ax</span> <span class="pl-c1">=</span> <span class="pl-s1">count_Series</span>.<span class="pl-s1">plot</span>.<span class="pl-en">bar</span>()  <span class="pl-c"># This yields incorrect graph</span>

<span class="pl-c"># If save it to a new .csv file and reload, though:</span>
<span class="pl-s1">categorical_DataFrame</span>.<span class="pl-en">to_csv</span>(<span class="pl-s">'saved_table.csv'</span>)
<span class="pl-s1">new_DataFrame</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_csv</span>(<span class="pl-s">'saved_table.csv'</span>, <span class="pl-s1">index_cols</span><span class="pl-c1">=</span><span class="pl-s">'GID'</span>)
<span class="pl-k">for</span> <span class="pl-s1">column_name</span> <span class="pl-c1">in</span> <span class="pl-s1">new_DataFrame</span>:
    <span class="pl-k">if</span> <span class="pl-en">str</span>(<span class="pl-s1">new_DataFrame</span>[<span class="pl-s1">column_name</span>].<span class="pl-s1">dtype</span>) <span class="pl-c1">is</span> <span class="pl-s">'category'</span>:
        <span class="pl-s1">count_Series</span> <span class="pl-c1">=</span> <span class="pl-s1">new_DataFrame</span>[<span class="pl-s1">column_name</span>].<span class="pl-en">value_counts</span>(<span class="pl-s1">dropna</span><span class="pl-c1">=</span><span class="pl-c1">False</span>) <span class="pl-c"># basically same operations</span>
        <span class="pl-en">print</span>(<span class="pl-s1">count_Series</span>)  <span class="pl-c"># Still correct</span>
        <span class="pl-s1">plt_ax</span> <span class="pl-c1">=</span> <span class="pl-s1">count_Series</span>.<span class="pl-s1">plot</span>.<span class="pl-en">bar</span>()  <span class="pl-c"># This now yields correct graphs.</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Most of the details have been commented in the code.</p>
<p dir="auto">In addition to that, the graphs are wrong in several aspects:<br>
The original table contains many values '-77' or '-77.0', which I substituted with np.nan and confirmed in the printout of Series.value_counts for each column; however, the plots still show none-zero counts of "-77".</p>
<p dir="auto">The counts of other values also contain mistakes (not all, but some).</p>
<p dir="auto">The 'GID' index column contains nan and duplicates, but that does not seem to affect value_counts() function as the sum of all groups' counts (including nan) always equals the total number of rows.</p>
<p dir="auto">Versions used:<br>
pandas: both 0.20.3 and newest version (v0.22.0)<br>
matplotlib: both 2.0.2 and 2.2.0, with and without explicit importing. (but I don't think it would affect pandas plotting)</p>
<p dir="auto">[this should explain <strong>why</strong> the current behaviour is a problem and why the expected output is a better solution.]</p>
<p dir="auto"><strong>Note</strong>: We receive a lot of issues on our GitHub tracker, so it is very possible that your issue has been posted before. Please check first before submitting so that we do not have to handle and close duplicates!</p>
<p dir="auto"><strong>Note</strong>: Many problems can be resolved by simply upgrading <code class="notranslate">pandas</code> to the latest version. Before submitting, please check if that solution works for you. If possible, you may want to check if <code class="notranslate">master</code> addresses this issue, but that is not necessary.</p>
<p dir="auto">For documentation-related issues, you can check the latest versions of the docs on <code class="notranslate">master</code> here:</p>
<p dir="auto"><a href="https://pandas-docs.github.io/pandas-docs-travis/" rel="nofollow">https://pandas-docs.github.io/pandas-docs-travis/</a></p>
<p dir="auto">If the issue has not been resolved there, go ahead and file it in the issue tracker.</p>
<h4 dir="auto">Expected Output</h4>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<h2 dir="auto">INSTALLED VERSIONS</h2>
<p dir="auto">commit: None<br>
python: 3.6.1.final.0<br>
python-bits: 64<br>
OS: Windows<br>
OS-release: 10<br>
machine: AMD64<br>
processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel<br>
byteorder: little<br>
LC_ALL: None<br>
LANG: en<br>
LOCALE: None.None</p>
<p dir="auto">pandas: 0.22.0<br>
pytest: 3.0.7<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.12.1<br>
scipy: 0.19.0<br>
pyarrow: None<br>
xarray: None<br>
IPython: 5.3.0<br>
sphinx: 1.5.6<br>
patsy: 0.4.1<br>
dateutil: 2.6.0<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: 1.2.1<br>
tables: 3.4.2<br>
numexpr: 2.6.2<br>
feather: None<br>
matplotlib: 2.2.0<br>
openpyxl: 2.4.7<br>
xlrd: 1.0.0<br>
xlwt: 1.2.0<br>
xlsxwriter: 0.9.6<br>
lxml: 3.7.3<br>
bs4: 4.6.0<br>
html5lib: 0.9999999<br>
sqlalchemy: 1.1.9<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.6<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.DataFrame().drop_duplicates()
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/home/analytical-monk/miniconda3/lib/python3.6/site-packages/pandas/core/frame.py&quot;, line 3098, in drop_duplicates
    duplicated = self.duplicated(subset, keep=keep)
  File &quot;/home/analytical-monk/miniconda3/lib/python3.6/site-packages/pandas/core/frame.py&quot;, line 3144, in duplicated
    labels, shape = map(list, zip(*map(f, vals)))
ValueError: not enough values to unpack (expected 2, got 0)"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>().<span class="pl-en">drop_duplicates</span>()
<span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  <span class="pl-v">File</span> <span class="pl-s">"&lt;stdin&gt;"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1</span>, <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
  <span class="pl-v">File</span> <span class="pl-s">"/home/analytical-monk/miniconda3/lib/python3.6/site-packages/pandas/core/frame.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">3098</span>, <span class="pl-s1">in</span> <span class="pl-s1">drop_duplicates</span>
    <span class="pl-s1">duplicated</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">duplicated</span>(<span class="pl-s1">subset</span>, <span class="pl-s1">keep</span><span class="pl-c1">=</span><span class="pl-s1">keep</span>)
  <span class="pl-v">File</span> <span class="pl-s">"/home/analytical-monk/miniconda3/lib/python3.6/site-packages/pandas/core/frame.py"</span>, <span class="pl-s1">line</span> <span class="pl-c1">3144</span>, <span class="pl-s1">in</span> <span class="pl-s1">duplicated</span>
    <span class="pl-s1">labels</span>, <span class="pl-s1">shape</span> <span class="pl-c1">=</span> <span class="pl-en">map</span>(<span class="pl-s1">list</span>, <span class="pl-en">zip</span>(<span class="pl-c1">*</span><span class="pl-en">map</span>(<span class="pl-s1">f</span>, <span class="pl-s1">vals</span>)))
<span class="pl-v">ValueError</span>: <span class="pl-c1">not</span> <span class="pl-s1">enough</span> <span class="pl-s1">values</span> <span class="pl-s1">to</span> <span class="pl-en">unpack</span> (<span class="pl-s1">expected</span> <span class="pl-c1">2</span>, <span class="pl-s1">got</span> <span class="pl-c1">0</span>)</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Currently, calling the drop_duplicates method for an empty dataframe object (simply pd.DataFrame()) throws an error.<br>
Ideally it should return back the empty dataframe just liked it does when at least one column is present.</p>
<h4 dir="auto">Expected Output</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.DataFrame().drop_duplicates()

Empty DataFrame
Columns: []
Index: []"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; pd.DataFrame().drop_duplicates()

Empty DataFrame
Columns: []
Index: []
</code></pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.8.0-58-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_IN
LOCALE: en_IN.ISO8859-1

pandas: 0.20.3
pytest: None
pip: 9.0.1
setuptools: 36.6.0
Cython: None
numpy: 1.13.1
scipy: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 1.0b10
sqlalchemy: 1.1.14
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.8.0-58-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_IN
LOCALE: en_IN.ISO8859-1

pandas: 0.20.3
pytest: None
pip: 9.0.1
setuptools: 36.6.0
Cython: None
numpy: 1.13.1
scipy: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.6.0
html5lib: 1.0b10
sqlalchemy: 1.1.14
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None
</code></pre></div>
</details>