<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
import pandas as pd
df = pd.DataFrame({'tms': pd.date_range('2017-1-1', '2017-1-31'), 'v': xrange(31)})
df_3 = pd.concat([df, df, df], axis=1)
# What I would like to do: df_3.drop_duplicates(axis=1)
deduplicated_df = df_3.T.drop_duplicates().T"><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-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>({<span class="pl-s">'tms'</span>: <span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s">'2017-1-1'</span>, <span class="pl-s">'2017-1-31'</span>), <span class="pl-s">'v'</span>: <span class="pl-en">xrange</span>(<span class="pl-c1">31</span>)})
<span class="pl-s1">df_3</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">concat</span>([<span class="pl-s1">df</span>, <span class="pl-s1">df</span>, <span class="pl-s1">df</span>], <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)
<span class="pl-c"># What I would like to do: df_3.drop_duplicates(axis=1)</span>
<span class="pl-s1">deduplicated_df</span> <span class="pl-c1">=</span> <span class="pl-s1">df_3</span>.<span class="pl-v">T</span>.<span class="pl-en">drop_duplicates</span>().<span class="pl-v">T</span></pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">Duplicate columns can be introduced when using the <code class="notranslate">pd.concat(axis=1)</code> method.</p>
<p dir="auto">It would be nice (not necessary) to use the <code class="notranslate">drop_duplicates</code> method with an <code class="notranslate">axis</code> parameter set to <code class="notranslate">1</code>.</p>
<p dir="auto">This can be implemented right now using: <code class="notranslate">df.T.drop_duplicates().T</code>. Maybe there is an alternative, better way.</p>
<p dir="auto">Notice that this isn't a  bug but a feature request/feature enhancement of an existing one.</p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="INSTALLED VERSIONS
------------------
commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Darwin
OS-release: 16.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: None.None

pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: None
Cython: None
numpy: 1.13.0
scipy: 0.19.1
statsmodels: 0.6.1
xarray: None
IPython: 4.0.2
sphinx: None
patsy: 0.4.0
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 2.0.2
openpyxl: None
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: 0.9.2
apiclient: 1.4.2
sqlalchemy: 1.1.11
pymysql: None
psycopg2: 2.7.1 (dt dec pq3 ext lo64)
jinja2: 2.9.6
boto: 2.47.0
pandas_datareader: None"><pre class="notranslate"><code class="notranslate">INSTALLED VERSIONS
------------------
commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Darwin
OS-release: 16.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: None.None

pandas: 0.19.2
nose: 1.3.7
pip: 9.0.1
setuptools: None
Cython: None
numpy: 1.13.0
scipy: 0.19.1
statsmodels: 0.6.1
xarray: None
IPython: 4.0.2
sphinx: None
patsy: 0.4.0
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 2.0.2
openpyxl: None
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: 0.9.2
apiclient: 1.4.2
sqlalchemy: 1.1.11
pymysql: None
psycopg2: 2.7.1 (dt dec pq3 ext lo64)
jinja2: 2.9.6
boto: 2.47.0
pandas_datareader: None
</code></pre></div>
<p dir="auto">Here is sample code that finds duplicate columns in a DataFrame based on their values (useful for cleaning data):</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="def duplicate_columns(frame):
    groups = frame.columns.to_series().groupby(frame.dtypes).groups
    dups = []
    for t, v in groups.items():
        dcols = frame[v].to_dict(orient=&quot;list&quot;)

        vs = dcols.values()
        ks = dcols.keys()
        lvs = len(vs)

        for i in range(lvs):
            for j in range(i+1,lvs):
                if vs[i] == vs[j]: 
                    dups.append(ks[i])
                    break

    return dups       "><pre class="notranslate"><span class="pl-k">def</span> <span class="pl-en">duplicate_columns</span>(<span class="pl-s1">frame</span>):
    <span class="pl-s1">groups</span> <span class="pl-c1">=</span> <span class="pl-s1">frame</span>.<span class="pl-s1">columns</span>.<span class="pl-en">to_series</span>().<span class="pl-en">groupby</span>(<span class="pl-s1">frame</span>.<span class="pl-s1">dtypes</span>).<span class="pl-s1">groups</span>
    <span class="pl-s1">dups</span> <span class="pl-c1">=</span> []
    <span class="pl-k">for</span> <span class="pl-s1">t</span>, <span class="pl-s1">v</span> <span class="pl-c1">in</span> <span class="pl-s1">groups</span>.<span class="pl-en">items</span>():
        <span class="pl-s1">dcols</span> <span class="pl-c1">=</span> <span class="pl-s1">frame</span>[<span class="pl-s1">v</span>].<span class="pl-en">to_dict</span>(<span class="pl-s1">orient</span><span class="pl-c1">=</span><span class="pl-s">"list"</span>)

        <span class="pl-s1">vs</span> <span class="pl-c1">=</span> <span class="pl-s1">dcols</span>.<span class="pl-en">values</span>()
        <span class="pl-s1">ks</span> <span class="pl-c1">=</span> <span class="pl-s1">dcols</span>.<span class="pl-en">keys</span>()
        <span class="pl-s1">lvs</span> <span class="pl-c1">=</span> <span class="pl-en">len</span>(<span class="pl-s1">vs</span>)

        <span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-s1">lvs</span>):
            <span class="pl-k">for</span> <span class="pl-s1">j</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-s1">i</span><span class="pl-c1">+</span><span class="pl-c1">1</span>,<span class="pl-s1">lvs</span>):
                <span class="pl-k">if</span> <span class="pl-s1">vs</span>[<span class="pl-s1">i</span>] <span class="pl-c1">==</span> <span class="pl-s1">vs</span>[<span class="pl-s1">j</span>]: 
                    <span class="pl-s1">dups</span>.<span class="pl-en">append</span>(<span class="pl-s1">ks</span>[<span class="pl-s1">i</span>])
                    <span class="pl-k">break</span>

    <span class="pl-k">return</span> <span class="pl-s1">dups</span>       </pre></div>
<p dir="auto">I've seen others suggest something like <code class="notranslate">df.T.drop_duplicates().T</code>.  However, transposing is a bad idea when working with large DataFrames.</p>
<p dir="auto">I would add a pull request, but I'm not sure I even know what that means.</p>