<h4 dir="auto">Code Sample</h4>
<p dir="auto">url = """<a href="https://en.wikipedia.org/wiki/List_of_winners_of_the_Boston_Marathon" rel="nofollow">https://en.wikipedia.org/wiki/List_of_winners_of_the_Boston_Marathon</a>"""<br>
tables = pd.read_html(url, header=0)<br>
print(tables[0].head())</p>
<h4 dir="auto">Problem description</h4>
<p dir="auto">The above code ''should' just extract the displayed text in the HTML table; what's in the dataframe should be what's displayed on screen. This isn't what happens. If the HTML contains a hyperlink with a title attribute, this is picked up and added to the dataframe, duplicating the data.</p>
<h4 dir="auto">Expected Output</h4>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   Year                   Athlete  \
0  1897          John J. McDermott   
1  1898         Ronald J. MacDonald   
2  1899          Lawrence Brignolia   
3  1900         John &quot;Jack&quot; Caffery   
4  1901         John &quot;Jack&quot; Caffery   

                      Country/State     Time        Notes  
0                United States (NY)  2:55:10          NaN  
1                     Canada Canada  2:42:00          NaN  
2                United States (MA)  2:54:38          NaN  
3                            Canada  2:39:44          NaN  
4                            Canada  2:29:23  2nd victory "><pre class="notranslate"><code class="notranslate">   Year                   Athlete  \
0  1897          John J. McDermott   
1  1898         Ronald J. MacDonald   
2  1899          Lawrence Brignolia   
3  1900         John "Jack" Caffery   
4  1901         John "Jack" Caffery   

                      Country/State     Time        Notes  
0                United States (NY)  2:55:10          NaN  
1                     Canada Canada  2:42:00          NaN  
2                United States (MA)  2:54:38          NaN  
3                            Canada  2:39:44          NaN  
4                            Canada  2:29:23  2nd victory 
</code></pre></div>
<h4 dir="auto">Output</h4>
<p dir="auto">Here's the actual output, the duplication is in the Athlete and Country/State columns.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="   Year                                  Athlete  
0  1897      McDermott, John J.John J. McDermott   
1  1898  MacDonald, Ronald J.Ronald J. MacDonald   
2  1899    Brignolia, LawrenceLawrence Brignolia   
3  1900         Caffery, JohnJohn &quot;Jack&quot; Caffery   
4  1901         Caffery, JohnJohn &quot;Jack&quot; Caffery   

                      Country/State     Time        Notes  
0  United States United States (NY)  2:55:10          NaN  
1                     Canada Canada  2:42:00          NaN  
2  United States United States (MA)  2:54:38          NaN  
3                     Canada Canada  2:39:44          NaN  
4                     Canada Canada  2:29:23  2nd victory "><pre class="notranslate"><code class="notranslate">   Year                                  Athlete  
0  1897      McDermott, John J.John J. McDermott   
1  1898  MacDonald, Ronald J.Ronald J. MacDonald   
2  1899    Brignolia, LawrenceLawrence Brignolia   
3  1900         Caffery, JohnJohn "Jack" Caffery   
4  1901         Caffery, JohnJohn "Jack" Caffery   

                      Country/State     Time        Notes  
0  United States United States (NY)  2:55:10          NaN  
1                     Canada Canada  2:42:00          NaN  
2  United States United States (MA)  2:54:38          NaN  
3                     Canada Canada  2:39:44          NaN  
4                     Canada Canada  2:29:23  2nd victory 
</code></pre></div>
<p dir="auto">It seems that the apply method of a group invokes the function passed as parameter once for each group, as expectes. However, the function is invoked twice for the first group. Enclose is a short code reproducing this behavior. Is it a normal behavior or am I doing something wrong here.</p>
<p dir="auto">I run the code with pandas 0.10.0 on. Windows 7, 32 bit version.</p>
<p dir="auto">The code reproducing this  behavior:</p>
<p dir="auto">import pandas as pd</p>
<p dir="auto">tdf      = pd.DataFrame( { 'cat' : [1,1,1,2,2,1,1,2], 'B' : range(8)})<br>
category = tdf['cat']<br>
pGroups = tdf.groupby(by=category)</p>
<p dir="auto">def getLen(df) :<br>
print  'len ',len(df)<br>
return len(df)</p>
<p dir="auto">plen = pGroups.apply(getLen)</p>