Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
table from wikipedia
#4
If look at Rank column df2['Rank'],see that not all countries get a Rank number but -.
This is correct as you see the same on website.
Change line 10 to this:
df0 = pd.read_html(str(sov_tables), na_values='ā€“')
Do df2.dtypes
Output:
Rank float64 Country name object Population int64 Date object % of world population object dtype: object
No int because of NaN values.
If need int most drop NaN with dropna().
df2['Rank'] = df2['Rank'].astype('int')
For Date do this.
df2['Date'] = pd.to_datetime(df2['Date'])
Output:
Rank int32 Country name object Population int64 Date datetime64[ns] % of world population object
One to go.
Reply


Messages In This Thread
table from wikipedia - by flow50 - Jun-27-2019, 10:31 AM
RE: table from wikipedia - by snippsat - Jun-27-2019, 12:47 PM
RE: table from wikipedia - by flow50 - Jun-28-2019, 03:02 PM
RE: table from wikipedia - by snippsat - Jun-28-2019, 05:22 PM
RE: table from wikipedia - by flow50 - Jul-01-2019, 12:16 PM
RE: table from wikipedia - by snippsat - Jul-01-2019, 07:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Scraping Wikipedia Article (Name in 1 column & URL in 2nd column) ->CSV! Anyone? BrandonKastning 4 2,056 Jan-27-2022, 04:36 AM
Last Post: Larz60+
  fetching, parsing data from Wikipedia apollo 2 3,572 May-06-2021, 08:08 PM
Last Post: snippsat
  Need help scraping wikipedia table bborusz2 6 3,282 Dec-01-2020, 11:31 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020