0

I'm using pandas to scrape a web page and iterate through a DataFrame object. Here's the function I'm calling:

def getTeamRoster(teamURL):
    teamPlayers = []
    table = pd.read_html(requests.get(teamURL).content)[4]
    nameTitle = '\n\t\t\t\tPlayers\n\t\t\t' 
    ratingTitle = 'SinglesRating'
    finalTable = table[[nameTitle, ratingTitle]][:-1]
    print(finalTable)
    for index, row in finalTable:
        print(index, row)

I'm using the syntax advocated here:

http://www.swegler.com/becky/blog/2014/08/06/useful-pandas-snippets/

However, I'm getting this error:

File "SquashScraper.py", line 46, in getTeamRoster
    for index, row in finalTable:
ValueError: too many values to unpack (expected 2)

For what it's worth, my finalTable prints as this:

   \n\t\t\t\tPlayers\n\t\t\t  SinglesRating
0                Browne,Noah           5.56
1             Ellis,Thornton           4.27
2                 Line,James           4.25
3          Desantis,Scott J.           5.08
4           Bahadori,Cameron           4.97
5              Groot,Michael           4.76
6              Ehsani,Darian           4.76
7                 Kardon,Max           4.83
8                 Van,Jeremy           4.66
9     Southmayd,Alexander T.           4.91
10        Cacouris,Stephen A           4.68
11         Groot,Christopher           4.62
12       Mack,Peter D. (sub)           3.94
13      Shrager,Nathaniel O.           0.00
14       Woolverton,Peter C.           4.06

which looks right to me.

Any idea why python doesn't like my syntax?

Thanks for the help, bclayman

1 Answer 1

1

You probably want to try this:

for index, row in finalTable.iterrows():
    print(index, row)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.