<p dir="auto">from <a href="http://stackoverflow.com/questions/29709918/pandas-and-category-replacement/29712287#29712287" rel="nofollow">SO</a></p>
<ul dir="auto">
<li>the <code class="notranslate">.add_categories</code> should be able to take an <code class="notranslate">Index</code>/ndarray, ATM it must be converted to a list</li>
<li>should be a keyword for something like: add any additional categories that I am passing to you (even if the current ones are duplicates, just add these to the end). e.g.</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [147]: s = pd.Categorical(list('aabbcd'))

In [148]: s2 = list('aabbcdefg')

In [149]: s
Out[149]: 
[a, a, b, b, c, d]
Categories (4, object): [a, b, c, d]

In [150]: s.add_categories(s.categories.sym_diff(Index(s2)).tolist())
Out[150]: 
[a, a, b, b, c, d]
Categories (7, object): [a, b, c, d, e, f, g]"><pre class="notranslate"><code class="notranslate">In [147]: s = pd.Categorical(list('aabbcd'))

In [148]: s2 = list('aabbcdefg')

In [149]: s
Out[149]: 
[a, a, b, b, c, d]
Categories (4, object): [a, b, c, d]

In [150]: s.add_categories(s.categories.sym_diff(Index(s2)).tolist())
Out[150]: 
[a, a, b, b, c, d]
Categories (7, object): [a, b, c, d, e, f, g]
</code></pre></div>
<p dir="auto">I would ideally just like to say:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="s.add_categories(s2, take_new=True)"><pre class="notranslate"><code class="notranslate">s.add_categories(s2, take_new=True)
</code></pre></div>
<p dir="auto">(maybe not the best keyword, but something like this)</p>
<p dir="auto">from the timeseries realease example: <a href="http://pandas.pydata.org/pandas-docs/version/0.19.0/whatsnew.html#merge-asof-for-asof-style-time-series-joining" rel="nofollow">http://pandas.pydata.org/pandas-docs/version/0.19.0/whatsnew.html#merge-asof-for-asof-style-time-series-joining</a><br>
making ticker as category:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="trades.ticker = trades.ticker.astype('category') 
quotes.ticker = quotes.ticker.astype('category') 

merge = pd.merge_asof(trades, quotes,
                  on='time',
                  by='ticker')"><pre class="notranslate"><span class="pl-s1">trades</span>.<span class="pl-s1">ticker</span> <span class="pl-c1">=</span> <span class="pl-s1">trades</span>.<span class="pl-s1">ticker</span>.<span class="pl-en">astype</span>(<span class="pl-s">'category'</span>) 
<span class="pl-s1">quotes</span>.<span class="pl-s1">ticker</span> <span class="pl-c1">=</span> <span class="pl-s1">quotes</span>.<span class="pl-s1">ticker</span>.<span class="pl-en">astype</span>(<span class="pl-s">'category'</span>) 

<span class="pl-s1">merge</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">merge_asof</span>(<span class="pl-s1">trades</span>, <span class="pl-s1">quotes</span>,
                  <span class="pl-s1">on</span><span class="pl-c1">=</span><span class="pl-s">'time'</span>,
                  <span class="pl-s1">by</span><span class="pl-c1">=</span><span class="pl-s">'ticker'</span>)</pre></div>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">merge.dtypes<br>
Out[31]:<br>
time        datetime64[ns]<br>
ticker            category<br>
price              float64<br>
quantity             int64<br>
bid                float64<br>
ask                float64</p>
<p dir="auto">geting :<br>
time        datetime64[ns]<br>
ticker              object<br>
price              float64<br>
quantity             int64<br>
bid                float64<br>
ask                float64</p>