Pandas returns string value from dataframe aggregate max() of count() function
<p>I am learning Pandas and struggling with the simpler stuff.</p>
<p>Ultimately I want my code to return only 'oranges' because is has the most occurrences of a value in the column COLOR.</p>
<p>My index is currently the x column.</p>
<pre><code>X    FRUIT   COLOR
10  apples  green
10  apples  red
10  oranges green
10  oranges orange
10  oranges yellow
10  bananas yellow
10  bananas green
</code></pre>
<p>I always seem to end up returning a key value pair or just the .count() number and can't seem to pull just the FRUIT column value from the aggregate results.</p>
<p>Here's one of my code samples trying to solve it - I've tried many but this is the latest one that's not working:</p>
<pre><code>df['COUNT'] = df.groupby(['FRUIT'])['FRUIT'].transform('SIZE')
copy_df = df
max = copy_df.loc[df['SIZE'] == copy_df['SIZE'].max()]
print(max)
</code></pre>
<p>This returns &quot;AttributeError:  'SeriesGroupBy' object has no attribute 'SIZE'&quot;  - I've had other tries with better results but I can tell I'm not getting anywhere fast.</p>