text_html_output_1.png
from bs4 import BeautifulSoup

import pandas as pd

import requests #library used to download web pages.

G = 6.674 * 10 ** (-11)
M_e = 5.97 * 10 ** 24
R_e = 6.37 * 10 ** 6
def escape_velocity():
    pass

import requests
URL = 'https://nssdc.gsfc.nasa.gov/planetary/factsheet/planet_table_ratio.html'

page = requests.get(URL)

page.status_code

HTMLstr = page.text

soup = BeautifulSoup(HTMLstr, 'html.parser')

soup.title

soup.a

all_links = soup.find_all('a')

all_tables = soup.find_all('table')
planet_table = soup.find('table')

A = []
B = []
C = []
D = []
E = []
F = []
G = []
H = []
I = []
J = []
K = []
for row in planet_table.findAll('tr'):
    body = row.findAll('td')
    cells = row.findAll('td')
    if len(cells) == 11:
        A.append(cells[0].find(text=True))
        B.append(cells[1].find(text=True))
        C.append(cells[2].find(text=True))
        D.append(cells[3].find(text=True))
        E.append(cells[4].find(text=True))
        F.append(cells[5].find(text=True))
        G.append(cells[6].find(text=True))
        H.append(cells[7].find(text=True))
        I.append(cells[8].find(text=True))
        J.append(cells[9].find(text=True))
        K.append(cells[10].find(text=True))

import pandas as pd
df = pd.DataFrame(A, columns=['Physical_Measurement'])
df['Mercury'] = B
df['Venus'] = C
df['Earth'] = D
df['Moon'] = E
df['Mars'] = F
df['Jupiter'] = G
df['Saturn'] = H
df['Uranus'] = I
df['Neptune'] = J
df['Pluto'] = K

df = df.fillna(0)
df = df.replace(to_replace='Unknown*', value=0)
df

df = df.drop(df.index[0])
df = df.drop(df.index[-1])
df

df.dtypes

df = df.applymap(lambda x: x.strip('*') if isinstance(x, str) else x)
df

df = df.replace(to_replace=['No', 'Yes', 'Unknown'], value=[0, 1, 2])
df