Reputation: 128
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 !
Upvotes: 3
Views: 5872
Reputation: 1142
Use this command to align column name:
standings_table = standings_table.reset_index()
Upvotes: 2
Reputation: 187
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?
Upvotes: 0