<p dir="auto">This might not necessarily a new thing since 0.14, but I find the output of group.head() not appropriate for a grouping:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="df = pd.DataFrame(np.random.randn(6,2))
df['A'] = [1,2,2,1,1,2]
df"><pre class="notranslate"><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-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">randn</span>(<span class="pl-c1">6</span>,<span class="pl-c1">2</span>))
<span class="pl-s1">df</span>[<span class="pl-s">'A'</span>] <span class="pl-c1">=</span> [<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">2</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">2</span>]
<span class="pl-s1">df</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="          0         1  A
0 -0.047101  0.828542  1
1  1.617815  0.362700  2
2  1.366453 -1.116897  2
3  0.086743 -0.611371  1
4  1.918440 -1.230909  1
5 -1.003828 -0.592541  2"><pre class="notranslate"><code class="notranslate">          0         1  A
0 -0.047101  0.828542  1
1  1.617815  0.362700  2
2  1.366453 -1.116897  2
3  0.086743 -0.611371  1
4  1.918440 -1.230909  1
5 -1.003828 -0.592541  2
</code></pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="g = df.groupby('A')
g.head(2)"><pre class="notranslate"><span class="pl-s1">g</span> <span class="pl-c1">=</span> <span class="pl-s1">df</span>.<span class="pl-en">groupby</span>(<span class="pl-s">'A'</span>)
<span class="pl-s1">g</span>.<span class="pl-en">head</span>(<span class="pl-c1">2</span>)</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="          0         1  A
0 -0.047101  0.828542  1
1  1.617815  0.362700  2
2  1.366453 -1.116897  2
3  0.086743 -0.611371  1"><pre class="notranslate"><code class="notranslate">          0         1  A
0 -0.047101  0.828542  1
1  1.617815  0.362700  2
2  1.366453 -1.116897  2
3  0.086743 -0.611371  1
</code></pre></div>
<p dir="auto">My expectation of the previous output would be:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="          0         1  A
0 -0.047101  0.828542  1
3  0.086743 -0.611371  1
1  1.617815  0.362700  2
2  1.366453 -1.116897  2"><pre class="notranslate"><code class="notranslate">          0         1  A
0 -0.047101  0.828542  1
3  0.086743 -0.611371  1
1  1.617815  0.362700  2
2  1.366453 -1.116897  2
</code></pre></div>
<p dir="auto">because, after all, this is the result of a grouping, so things should be displayed grouped, shouldn't they?</p>
<p dir="auto">When <code class="notranslate">sort = True</code> is passed to <code class="notranslate">groupby</code> (which is by default) the groups will be in sorted order. If you loop through them they are in sorted order, if you compute the mean, std... they are in sorted order but if you use the method <code class="notranslate">head</code> they are NOT in sorted order.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
import pandas as pd

df = pd.DataFrame([[2, 100], [2, 200], [2, 300], [1, 400], [1, 500], [1, 600]], columns = ['A', 'B'])

grouped = df.groupby(df['A'], sort = True)
for name, group in grouped:
    print(group)
print(grouped.mean())
print(grouped.head(1))"><pre class="notranslate"><code class="notranslate">
import pandas as pd

df = pd.DataFrame([[2, 100], [2, 200], [2, 300], [1, 400], [1, 500], [1, 600]], columns = ['A', 'B'])

grouped = df.groupby(df['A'], sort = True)
for name, group in grouped:
    print(group)
print(grouped.mean())
print(grouped.head(1))
</code></pre></div>
<p dir="auto">Is this expected? I have not found this behaviour documented.<br>
I think it is confusing and has caused me a headache because I was combining output of the <code class="notranslate">mean</code> and <code class="notranslate">head</code> methods in the same DataFrame, and since the data was not ordered before those results were getting mixed because of these order issues. I have pandas 0.20.3</p>