3

small problem here- more an aesthetic issue with Pandas. Basically- I am just reading a table (read_html) from the internet, and then printing it out. The column names are not aligned-- on a different row.

import pandas as pd

standings = pd.read_html("http://soccerleague.org", index_col=0)
standings_table = standings[0][["PTS", "PF", "PA"]]
print(standings_table)

This prints out:

                    PTS  PF  PA
Team                           
Spain                20  48  16
France               15  41  26
Germany              13  46  34
United Kingdom       10  34  33
Brazil                8  33  42
Argentina             4  22  35
Uruguay               4  23  34
Russia                2  20  47

Process finished with exit code 0

The table is correct. But, I would like the PTS, PF, PA column names to be on the same row as "Team" column name. I cant find any info on this , any help would be great !

2 Answers 2

2

Use this command to align column name:

standings_table = standings_table.reset_index()
Sign up to request clarification or add additional context in comments.

Comments

0

It looks as though 'Team' is counted as an element, not a column title, perhaps

standings_table = wdl_standings[0][["Team","PTS", "PF", "PA"]]

would work?

1 Comment

I set the "Team" column to be the index in index_col=0 . But your code does help if I remove the index_col statement. But then I get a pesky 0-7 index on the left that I also dont want in the table see imgur.com/a/Q9wF8

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.