<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import pandas as pd
import numpy as np
print(&quot;Pandas version: &quot;, pd.__version__) # mine: 0.21.0
print(&quot;Numpy version: &quot;, np.__version__) # mine: 1.13.3

# generate some data
data = np.random.randn(1,20)
target = np.array( ['Test'] * len(data) ).reshape(-1,1)

data_and_target = np.hstack((data, target))
data_and_target_cols = [&quot;c&quot; + str(i) for i in range(data.shape[1])] + ['target']
data_and_target_df = pd.DataFrame(data_and_target, columns=data_and_target_cols)

print(data_and_target_df[data_and_target_df.columns.difference(['target'])].columns)

# the column order I would have expected / &quot;workaround&quot;
print(data_and_target_df[data_and_target_df.columns.values[~data_and_target_df.columns.str.contains('target')]].columns )
"><pre class="notranslate"><code class="notranslate">import pandas as pd
import numpy as np
print("Pandas version: ", pd.__version__) # mine: 0.21.0
print("Numpy version: ", np.__version__) # mine: 1.13.3

# generate some data
data = np.random.randn(1,20)
target = np.array( ['Test'] * len(data) ).reshape(-1,1)

data_and_target = np.hstack((data, target))
data_and_target_cols = ["c" + str(i) for i in range(data.shape[1])] + ['target']
data_and_target_df = pd.DataFrame(data_and_target, columns=data_and_target_cols)

print(data_and_target_df[data_and_target_df.columns.difference(['target'])].columns)

# the column order I would have expected / "workaround"
print(data_and_target_df[data_and_target_df.columns.values[~data_and_target_df.columns.str.contains('target')]].columns )

</code></pre></div>
<h4 dir="auto">Problem description</h4>
<ul dir="auto">
<li>
<p dir="auto">I assumed that pandas.columns.difference has the same functionality as the longer expression given above under workaround.</p>
</li>
<li>
<p dir="auto">It took me a long time to discover that "Index.difference" does not only remove the column but also sorts them in a lexical order.</p>
</li>
<li>
<p dir="auto">This can cause major issues e.g. when transforming the table into numpy via DataFrame.values while not tracking columns.</p>
</li>
<li>
<p dir="auto">It took me a long time to figure out that the degraded performance in my system was due to this call. I now know that the sorting is a documented feature; but maybe this is not an ideal behavior.</p>
</li>
<li>
<p dir="auto">By reporting this I would like to put this to the discussion</p>
</li>
</ul>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.3.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
<p dir="auto">pandas: 0.21.0<br>
pytest: None<br>
pip: 9.0.1<br>
setuptools: 33.1.1.post20170320<br>
Cython: None<br>
numpy: 1.13.3<br>
scipy: 0.19.0<br>
pyarrow: None<br>
xarray: None<br>
IPython: 5.3.0<br>
sphinx: None<br>
patsy: 0.4.1<br>
dateutil: 2.6.0<br>
pytz: 2017.2<br>
blosc: None<br>
bottleneck: None<br>
tables: 3.4.2<br>
numexpr: 2.6.2<br>
feather: None<br>
matplotlib: None<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: 0.999<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: 2.9.5<br>
s3fs: None<br>
fastparquet: None<br>
pandas_gbq: None<br>
pandas_datareader: None</p>
</details>
<p dir="auto">I often want to remove certain elements from an index while retaining the original ordering of the index. For this reason a sort keyword in the <code class="notranslate">index.difference</code> method would be required:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In: index = pd.Index([0, 1, 2, 4, 3])
In: index.difference({1, 2})
Out: Int64Index([0, 3, 4], dtype='int64')
# It would be cool to have instead
In: index.difference({1, 2}, sort=False)
Out: Int64Index([0, 4, 3], dtype='int64')"><pre class="notranslate"><code class="notranslate">In: index = pd.Index([0, 1, 2, 4, 3])
In: index.difference({1, 2})
Out: Int64Index([0, 3, 4], dtype='int64')
# It would be cool to have instead
In: index.difference({1, 2}, sort=False)
Out: Int64Index([0, 4, 3], dtype='int64')
</code></pre></div>
<p dir="auto">I think that this usecase appears frequently and setting the default to <code class="notranslate">sort=True</code> doesn't affect existing code.</p>