<p dir="auto">Referenced briefly in the OP at <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="12907834" data-permission-text="Title is private" data-url="https://github.com/pandas-dev/pandas/issues/3275" data-hovercard-type="issue" data-hovercard-url="/pandas-dev/pandas/issues/3275/hovercard" href="https://github.com/pandas-dev/pandas/issues/3275">#3275</a></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [11]: idx = pd.MultiIndex.from_tuples([('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2), ('b', 3)])

In [12]: idx.names = ['outer', 'inner']

In [13]: df = pd.DataFrame({&quot;A&quot;: np.arange(6), 'B': ['one', 'one', 'two', 'two', 'one', 'one']}, index=idx)"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">11</span>]: <span class="pl-s1">idx</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>.<span class="pl-en">from_tuples</span>([(<span class="pl-s">'a'</span>, <span class="pl-c1">1</span>), (<span class="pl-s">'a'</span>, <span class="pl-c1">2</span>), (<span class="pl-s">'a'</span>, <span class="pl-c1">3</span>), (<span class="pl-s">'b'</span>, <span class="pl-c1">1</span>), (<span class="pl-s">'b'</span>, <span class="pl-c1">2</span>), (<span class="pl-s">'b'</span>, <span class="pl-c1">3</span>)])

<span class="pl-v">In</span> [<span class="pl-c1">12</span>]: <span class="pl-s1">idx</span>.<span class="pl-s1">names</span> <span class="pl-c1">=</span> [<span class="pl-s">'outer'</span>, <span class="pl-s">'inner'</span>]

<span class="pl-v">In</span> [<span class="pl-c1">13</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">"A"</span>: <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">6</span>), <span class="pl-s">'B'</span>: [<span class="pl-s">'one'</span>, <span class="pl-s">'one'</span>, <span class="pl-s">'two'</span>, <span class="pl-s">'two'</span>, <span class="pl-s">'one'</span>, <span class="pl-s">'one'</span>]}, <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">idx</span>)</pre></div>
<p dir="auto">So the idea is to be able to call</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="df.groupby('B', level='inner')"><pre class="notranslate"><span class="pl-s1">df</span>.<span class="pl-en">groupby</span>(<span class="pl-s">'B'</span>, <span class="pl-s1">level</span><span class="pl-c1">=</span><span class="pl-s">'inner'</span>)</pre></div>
<p dir="auto">instead of</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [15]: df.reset_index().groupby(['B', 'inner']).mean()
Out[15]: 
             A
B   inner     
one 1      0.0
    2      2.5
    3      5.0
two 1      3.0
    3      2.0

[5 rows x 1 columns]"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">15</span>]: <span class="pl-s1">df</span>.<span class="pl-en">reset_index</span>().<span class="pl-en">groupby</span>([<span class="pl-s">'B'</span>, <span class="pl-s">'inner'</span>]).<span class="pl-en">mean</span>()
<span class="pl-v">Out</span>[<span class="pl-c1">15</span>]: 
             <span class="pl-v">A</span>
<span class="pl-v">B</span>   <span class="pl-s1">inner</span>     
<span class="pl-s1">one</span> <span class="pl-c1">1</span>      <span class="pl-c1">0.0</span>
    <span class="pl-c1">2</span>      <span class="pl-c1">2.5</span>
    <span class="pl-c1">3</span>      <span class="pl-c1">5.0</span>
<span class="pl-s1">two</span> <span class="pl-c1">1</span>      <span class="pl-c1">3.0</span>
    <span class="pl-c1">3</span>      <span class="pl-c1">2.0</span>

[<span class="pl-c1">5</span> <span class="pl-s1">rows</span> <span class="pl-s1">x</span> <span class="pl-c1">1</span> <span class="pl-s1">columns</span>]</pre></div>
<p dir="auto">Currently this raises <code class="notranslate">TypeError: 'numpy.ndarray' object is not callable</code>.  Mostly just syntactic sugar, but I've been having to do a lot of this lately and all the <code class="notranslate">reset_index</code>es are getting annoying. Thoughts?</p>
<p dir="auto">I have created a <a href="https://github.com/toobaz/pandas/tree/style_to_latex">branch</a> adding a <code class="notranslate">to_latex</code> method to <code class="notranslate">Styler</code>.</p>
<p dir="auto">It is nowhere near readiness, and in particular:</p>
<ul dir="auto">
<li>supports only cell background color as of now - adding some attributes should be trivial, adding others might be less so</li>
<li>most importantly, it works on a copy of the dataframe casted <code class="notranslate">.astype(str)</code>, which is plain wrong because it discards features such as float formatting. For a good result, a better integration is needed with the code that currently does cell formatting in <code class="notranslate">DataFrame.to_latex</code>.</li>
</ul>
<p dir="auto">This said, if anyone feels like experimenting, it might be slightly better than starting from scratch.</p>
<p dir="auto">One aspect which I think is useful, even aside from this branch, and might benefit some discussion, is the pair of methods <code class="notranslate">_latex_preserve</code> and <code class="notranslate">_latex_restore</code>, which basically replace LaTeX commands so that they are not disturbed by escaping, and then restores them. There might be better way to code this, but I really think this is something we need to implement, and to offer to users who happen to nest LaTeX code in their cells.</p>