Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To obtain the unique values in a column you can use the <a href="http://pandas.pydata.org/pandas-docs/dev/generated/pandas.Series.unique.html#pandas.Series.unique" rel="nofollow noreferrer"><code>unique</code></a> Series method, which will return a numpy array of the unique values <em>(and it is fast!)</em>.</p> <pre><code>df.long.unique() # returns numpy array of unique values </code></pre> <p>You could then use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.append.html" rel="nofollow noreferrer"><code>numpy.append</code></a>:</p> <pre><code>np.append(df.long.unique(), df.short.unique()) </code></pre> <p>Note: This just appends the two unique results together and so itself is not unique!</p> <p>.</p> <p>Here's a (trivial) example:</p> <pre><code>import pandas as pd import numpy as np df = pd.DataFrame([[1, 2], [1, 4]], columns=['long','short']) In [4]: df Out[4]: long short 0 1 2 1 1 4 In [5]: df.long.unique() Out[5]: array([1]) In [6]: df.short.unique() Out[6]: array([2, 4]) </code></pre> <p>And then <a href="https://stackoverflow.com/a/9775378/1240268">appending the resulting two arrays</a>:</p> <pre><code>In [7]: np.append(df.long.unique(), df.short.unique()) Out[7]: array([1, 2, 4]) </code></pre> <p>Using @Zalazny7's <code>set</code> is significantly faster (since it runs over the array only once) and somewhat upsettingly it's even faster than <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.unique.html" rel="nofollow noreferrer"><code>np.unique</code></a> <em>(which sorts the resulting array!)</em>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload