Solar System

Solar System

Import packages

In [1]:
import numpy as np
import pandas as pd

Get Data

URL of the webpage from where we will get data

In [2]:
webpage = "https://nssdc.gsfc.nasa.gov/planetary/factsheet/planet_table_ratio.html"
webpage
Out[2]:
'https://nssdc.gsfc.nasa.gov/planetary/factsheet/planet_table_ratio.html'

load data from webpage into our program

In [3]:
tables = pd.read_html(webpage, header = 0)
tables
Out[3]:
[                Unnamed: 0  MERCURY   VENUS  EARTH      MOON   MARS   JUPITER  \
 0                     Mass   0.0553   0.815      1    0.0123  0.107     317.8   
 1                 Diameter    0.383   0.949      1    0.2724  0.532     11.21   
 2                  Density    0.984   0.951      1     0.605  0.713     0.240   
 3                  Gravity    0.378   0.907      1     0.166  0.377      2.36   
 4          Escape Velocity    0.384   0.926      1     0.213  0.450      5.32   
 5          Rotation Period     58.8    -244      1      27.4   1.03     0.415   
 6            Length of Day    175.9   116.8      1      29.5   1.03     0.414   
 7        Distance from Sun    0.387   0.723      1  0.00257*   1.52      5.20   
 8               Perihelion    0.313   0.731      1  0.00247*   1.41      5.03   
 9                 Aphelion    0.459   0.716      1  0.00267*   1.64      5.37   
 10          Orbital Period    0.241   0.615      1   0.0748*   1.88      11.9   
 11        Orbital Velocity     1.59    1.18      1   0.0343*  0.808     0.439   
 12    Orbital Eccentricity     12.3   0.401      1      3.29   5.60      2.93   
 13      Obliquity to Orbit    0.001  0.113*      1     0.285   1.07     0.134   
 14        Surface Pressure        0      92      1         0   0.01  Unknown*   
 15         Number of Moons        0       0      1         0      2        79   
 16            Ring System?       No      No     No        No     No       Yes   
 17  Global Magnetic Field?      Yes      No    Yes        No     No       Yes   
 18                     NaN  MERCURY   VENUS  EARTH      MOON   MARS   JUPITER   
 
       SATURN    URANUS   NEPTUNE    PLUTO  
 0       95.2      14.5      17.1   0.0025  
 1       9.45      4.01      3.88    0.186  
 2      0.125     0.230     0.297    0.380  
 3      0.916     0.889      1.12    0.071  
 4       3.17      1.90      2.10    0.116  
 5      0.445    -0.720     0.673     6.41  
 6      0.444     0.718     0.671     6.39  
 7       9.58     19.20     30.05    39.48  
 8       9.20     18.64     30.22    30.16  
 9       9.96     19.75     29.89    48.49  
 10      29.4      83.7     163.7    247.9  
 11     0.325     0.228     0.182    0.157  
 12      3.38      2.74     0.677     14.6  
 13      1.14     4.17*      1.21    2.45*  
 14  Unknown*  Unknown*  Unknown*  0.00001  
 15        82        27        14        5  
 16       Yes       Yes       Yes       No  
 17       Yes       Yes       Yes  Unknown  
 18    SATURN    URANUS   NEPTUNE    PLUTO  ]

Get the table

When we load data from a webpage, there may be many tables in that page, we need only first table.

The counting starts from 0. So first table is tables[0]. We will call this table ss.

In [4]:
ss = tables[0]
ss
Out[4]:
Unnamed: 0 MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
0 Mass 0.0553 0.815 1 0.0123 0.107 317.8 95.2 14.5 17.1 0.0025
1 Diameter 0.383 0.949 1 0.2724 0.532 11.21 9.45 4.01 3.88 0.186
2 Density 0.984 0.951 1 0.605 0.713 0.240 0.125 0.230 0.297 0.380
3 Gravity 0.378 0.907 1 0.166 0.377 2.36 0.916 0.889 1.12 0.071
4 Escape Velocity 0.384 0.926 1 0.213 0.450 5.32 3.17 1.90 2.10 0.116
5 Rotation Period 58.8 -244 1 27.4 1.03 0.415 0.445 -0.720 0.673 6.41
6 Length of Day 175.9 116.8 1 29.5 1.03 0.414 0.444 0.718 0.671 6.39
7 Distance from Sun 0.387 0.723 1 0.00257* 1.52 5.20 9.58 19.20 30.05 39.48
8 Perihelion 0.313 0.731 1 0.00247* 1.41 5.03 9.20 18.64 30.22 30.16
9 Aphelion 0.459 0.716 1 0.00267* 1.64 5.37 9.96 19.75 29.89 48.49
10 Orbital Period 0.241 0.615 1 0.0748* 1.88 11.9 29.4 83.7 163.7 247.9
11 Orbital Velocity 1.59 1.18 1 0.0343* 0.808 0.439 0.325 0.228 0.182 0.157
12 Orbital Eccentricity 12.3 0.401 1 3.29 5.60 2.93 3.38 2.74 0.677 14.6
13 Obliquity to Orbit 0.001 0.113* 1 0.285 1.07 0.134 1.14 4.17* 1.21 2.45*
14 Surface Pressure 0 92 1 0 0.01 Unknown* Unknown* Unknown* Unknown* 0.00001
15 Number of Moons 0 0 1 0 2 79 82 27 14 5
16 Ring System? No No No No No Yes Yes Yes Yes No
17 Global Magnetic Field? Yes No Yes No No Yes Yes Yes Yes Unknown
18 NaN MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO

How to see specific records?

First five records

Use any of the followings:

ss.head() ss.head(5) ss[0:5] ss[:5]
In [5]:
ss.head()
Out[5]:
Unnamed: 0 MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
0 Mass 0.0553 0.815 1 0.0123 0.107 317.8 95.2 14.5 17.1 0.0025
1 Diameter 0.383 0.949 1 0.2724 0.532 11.21 9.45 4.01 3.88 0.186
2 Density 0.984 0.951 1 0.605 0.713 0.240 0.125 0.230 0.297 0.380
3 Gravity 0.378 0.907 1 0.166 0.377 2.36 0.916 0.889 1.12 0.071
4 Escape Velocity 0.384 0.926 1 0.213 0.450 5.32 3.17 1.90 2.10 0.116

See records in steps

See fisrt 5 records, see every alternate record

In [6]:
ss[0:5:2]
Out[6]:
Unnamed: 0 MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
0 Mass 0.0553 0.815 1 0.0123 0.107 317.8 95.2 14.5 17.1 0.0025
2 Density 0.984 0.951 1 0.605 0.713 0.240 0.125 0.230 0.297 0.380
4 Escape Velocity 0.384 0.926 1 0.213 0.450 5.32 3.17 1.90 2.10 0.116

See fisrt 10 records, see every 3rd record

In [7]:
ss[0:10:3]
Out[7]:
Unnamed: 0 MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
0 Mass 0.0553 0.815 1 0.0123 0.107 317.8 95.2 14.5 17.1 0.0025
3 Gravity 0.378 0.907 1 0.166 0.377 2.36 0.916 0.889 1.12 0.071
6 Length of Day 175.9 116.8 1 29.5 1.03 0.414 0.444 0.718 0.671 6.39
9 Aphelion 0.459 0.716 1 0.00267* 1.64 5.37 9.96 19.75 29.89 48.49

See records 10 to 19, see every 3rd record

In [8]:
ss[10:19:3]
Out[8]:
Unnamed: 0 MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
10 Orbital Period 0.241 0.615 1 0.0748* 1.88 11.9 29.4 83.7 163.7 247.9
13 Obliquity to Orbit 0.001 0.113* 1 0.285 1.07 0.134 1.14 4.17* 1.21 2.45*
16 Ring System? No No No No No Yes Yes Yes Yes No

See all records

In [9]:
ss[:]
Out[9]:
Unnamed: 0 MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
0 Mass 0.0553 0.815 1 0.0123 0.107 317.8 95.2 14.5 17.1 0.0025
1 Diameter 0.383 0.949 1 0.2724 0.532 11.21 9.45 4.01 3.88 0.186
2 Density 0.984 0.951 1 0.605 0.713 0.240 0.125 0.230 0.297 0.380
3 Gravity 0.378 0.907 1 0.166 0.377 2.36 0.916 0.889 1.12 0.071
4 Escape Velocity 0.384 0.926 1 0.213 0.450 5.32 3.17 1.90 2.10 0.116
5 Rotation Period 58.8 -244 1 27.4 1.03 0.415 0.445 -0.720 0.673 6.41
6 Length of Day 175.9 116.8 1 29.5 1.03 0.414 0.444 0.718 0.671 6.39
7 Distance from Sun 0.387 0.723 1 0.00257* 1.52 5.20 9.58 19.20 30.05 39.48
8 Perihelion 0.313 0.731 1 0.00247* 1.41 5.03 9.20 18.64 30.22 30.16
9 Aphelion 0.459 0.716 1 0.00267* 1.64 5.37 9.96 19.75 29.89 48.49
10 Orbital Period 0.241 0.615 1 0.0748* 1.88 11.9 29.4 83.7 163.7 247.9
11 Orbital Velocity 1.59 1.18 1 0.0343* 0.808 0.439 0.325 0.228 0.182 0.157
12 Orbital Eccentricity 12.3 0.401 1 3.29 5.60 2.93 3.38 2.74 0.677 14.6
13 Obliquity to Orbit 0.001 0.113* 1 0.285 1.07 0.134 1.14 4.17* 1.21 2.45*
14 Surface Pressure 0 92 1 0 0.01 Unknown* Unknown* Unknown* Unknown* 0.00001
15 Number of Moons 0 0 1 0 2 79 82 27 14 5
16 Ring System? No No No No No Yes Yes Yes Yes No
17 Global Magnetic Field? Yes No Yes No No Yes Yes Yes Yes Unknown
18 NaN MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO

Last 4 records

In [10]:
ss[-4:]
Out[10]:
Unnamed: 0 MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
15 Number of Moons 0 0 1 0 2 79 82 27 14 5
16 Ring System? No No No No No Yes Yes Yes Yes No
17 Global Magnetic Field? Yes No Yes No No Yes Yes Yes Yes Unknown
18 NaN MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO

See 5th last to 3rd last

In [11]:
ss[-10:]
Out[11]:
Unnamed: 0 MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
9 Aphelion 0.459 0.716 1 0.00267* 1.64 5.37 9.96 19.75 29.89 48.49
10 Orbital Period 0.241 0.615 1 0.0748* 1.88 11.9 29.4 83.7 163.7 247.9
11 Orbital Velocity 1.59 1.18 1 0.0343* 0.808 0.439 0.325 0.228 0.182 0.157
12 Orbital Eccentricity 12.3 0.401 1 3.29 5.60 2.93 3.38 2.74 0.677 14.6
13 Obliquity to Orbit 0.001 0.113* 1 0.285 1.07 0.134 1.14 4.17* 1.21 2.45*
14 Surface Pressure 0 92 1 0 0.01 Unknown* Unknown* Unknown* Unknown* 0.00001
15 Number of Moons 0 0 1 0 2 79 82 27 14 5
16 Ring System? No No No No No Yes Yes Yes Yes No
17 Global Magnetic Field? Yes No Yes No No Yes Yes Yes Yes Unknown
18 NaN MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO

Index of our table

As you will see, it is a range of integers, from 0 to 19.

Please note that range(0, 19) starts with 0 and ends at 18. It does not include 19.

In [12]:
ss.index
Out[12]:
RangeIndex(start=0, stop=19, step=1)

Coulumns of our tables

In [13]:
ss.columns
Out[13]:
Index(['Unnamed: 0', 'MERCURY', 'VENUS', 'EARTH', 'MOON', 'MARS', 'JUPITER',
       'SATURN', 'URANUS', 'NEPTUNE', 'PLUTO'],
      dtype='object')

Rename the first column

In [14]:
ss.rename(columns =
          {'Unnamed: 0': 'properties'}, 
          inplace=True)
In [15]:
ss.columns
Out[15]:
Index(['properties', 'MERCURY', 'VENUS', 'EARTH', 'MOON', 'MARS', 'JUPITER',
       'SATURN', 'URANUS', 'NEPTUNE', 'PLUTO'],
      dtype='object')
In [16]:
ss = ss.set_index('properties')
ss
Out[16]:
MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
properties
Mass 0.0553 0.815 1 0.0123 0.107 317.8 95.2 14.5 17.1 0.0025
Diameter 0.383 0.949 1 0.2724 0.532 11.21 9.45 4.01 3.88 0.186
Density 0.984 0.951 1 0.605 0.713 0.240 0.125 0.230 0.297 0.380
Gravity 0.378 0.907 1 0.166 0.377 2.36 0.916 0.889 1.12 0.071
Escape Velocity 0.384 0.926 1 0.213 0.450 5.32 3.17 1.90 2.10 0.116
Rotation Period 58.8 -244 1 27.4 1.03 0.415 0.445 -0.720 0.673 6.41
Length of Day 175.9 116.8 1 29.5 1.03 0.414 0.444 0.718 0.671 6.39
Distance from Sun 0.387 0.723 1 0.00257* 1.52 5.20 9.58 19.20 30.05 39.48
Perihelion 0.313 0.731 1 0.00247* 1.41 5.03 9.20 18.64 30.22 30.16
Aphelion 0.459 0.716 1 0.00267* 1.64 5.37 9.96 19.75 29.89 48.49
Orbital Period 0.241 0.615 1 0.0748* 1.88 11.9 29.4 83.7 163.7 247.9
Orbital Velocity 1.59 1.18 1 0.0343* 0.808 0.439 0.325 0.228 0.182 0.157
Orbital Eccentricity 12.3 0.401 1 3.29 5.60 2.93 3.38 2.74 0.677 14.6
Obliquity to Orbit 0.001 0.113* 1 0.285 1.07 0.134 1.14 4.17* 1.21 2.45*
Surface Pressure 0 92 1 0 0.01 Unknown* Unknown* Unknown* Unknown* 0.00001
Number of Moons 0 0 1 0 2 79 82 27 14 5
Ring System? No No No No No Yes Yes Yes Yes No
Global Magnetic Field? Yes No Yes No No Yes Yes Yes Yes Unknown
NaN MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
In [17]:
ss.index
Out[17]:
Index([                  'Mass',               'Diameter',
                      'Density',                'Gravity',
              'Escape Velocity',        'Rotation Period',
                'Length of Day',      'Distance from Sun',
                   'Perihelion',               'Aphelion',
               'Orbital Period',       'Orbital Velocity',
         'Orbital Eccentricity',     'Obliquity to Orbit',
             'Surface Pressure',        'Number of Moons',
                 'Ring System?', 'Global Magnetic Field?',
                            nan],
      dtype='object', name='properties')
In [18]:
ss.columns
Out[18]:
Index(['MERCURY', 'VENUS', 'EARTH', 'MOON', 'MARS', 'JUPITER', 'SATURN',
       'URANUS', 'NEPTUNE', 'PLUTO'],
      dtype='object')

Interchange rows and columns

It is called transpose.

In [19]:
ss.T
Out[19]:
properties Mass Diameter Density Gravity Escape Velocity Rotation Period Length of Day Distance from Sun Perihelion Aphelion Orbital Period Orbital Velocity Orbital Eccentricity Obliquity to Orbit Surface Pressure Number of Moons Ring System? Global Magnetic Field? NaN
MERCURY 0.0553 0.383 0.984 0.378 0.384 58.8 175.9 0.387 0.313 0.459 0.241 1.59 12.3 0.001 0 0 No Yes MERCURY
VENUS 0.815 0.949 0.951 0.907 0.926 -244 116.8 0.723 0.731 0.716 0.615 1.18 0.401 0.113* 92 0 No No VENUS
EARTH 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 No Yes EARTH
MOON 0.0123 0.2724 0.605 0.166 0.213 27.4 29.5 0.00257* 0.00247* 0.00267* 0.0748* 0.0343* 3.29 0.285 0 0 No No MOON
MARS 0.107 0.532 0.713 0.377 0.450 1.03 1.03 1.52 1.41 1.64 1.88 0.808 5.60 1.07 0.01 2 No No MARS
JUPITER 317.8 11.21 0.240 2.36 5.32 0.415 0.414 5.20 5.03 5.37 11.9 0.439 2.93 0.134 Unknown* 79 Yes Yes JUPITER
SATURN 95.2 9.45 0.125 0.916 3.17 0.445 0.444 9.58 9.20 9.96 29.4 0.325 3.38 1.14 Unknown* 82 Yes Yes SATURN
URANUS 14.5 4.01 0.230 0.889 1.90 -0.720 0.718 19.20 18.64 19.75 83.7 0.228 2.74 4.17* Unknown* 27 Yes Yes URANUS
NEPTUNE 17.1 3.88 0.297 1.12 2.10 0.673 0.671 30.05 30.22 29.89 163.7 0.182 0.677 1.21 Unknown* 14 Yes Yes NEPTUNE
PLUTO 0.0025 0.186 0.380 0.071 0.116 6.41 6.39 39.48 30.16 48.49 247.9 0.157 14.6 2.45* 0.00001 5 No Unknown PLUTO
In [20]:
ss
Out[20]:
MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO
properties
Mass 0.0553 0.815 1 0.0123 0.107 317.8 95.2 14.5 17.1 0.0025
Diameter 0.383 0.949 1 0.2724 0.532 11.21 9.45 4.01 3.88 0.186
Density 0.984 0.951 1 0.605 0.713 0.240 0.125 0.230 0.297 0.380
Gravity 0.378 0.907 1 0.166 0.377 2.36 0.916 0.889 1.12 0.071
Escape Velocity 0.384 0.926 1 0.213 0.450 5.32 3.17 1.90 2.10 0.116
Rotation Period 58.8 -244 1 27.4 1.03 0.415 0.445 -0.720 0.673 6.41
Length of Day 175.9 116.8 1 29.5 1.03 0.414 0.444 0.718 0.671 6.39
Distance from Sun 0.387 0.723 1 0.00257* 1.52 5.20 9.58 19.20 30.05 39.48
Perihelion 0.313 0.731 1 0.00247* 1.41 5.03 9.20 18.64 30.22 30.16
Aphelion 0.459 0.716 1 0.00267* 1.64 5.37 9.96 19.75 29.89 48.49
Orbital Period 0.241 0.615 1 0.0748* 1.88 11.9 29.4 83.7 163.7 247.9
Orbital Velocity 1.59 1.18 1 0.0343* 0.808 0.439 0.325 0.228 0.182 0.157
Orbital Eccentricity 12.3 0.401 1 3.29 5.60 2.93 3.38 2.74 0.677 14.6
Obliquity to Orbit 0.001 0.113* 1 0.285 1.07 0.134 1.14 4.17* 1.21 2.45*
Surface Pressure 0 92 1 0 0.01 Unknown* Unknown* Unknown* Unknown* 0.00001
Number of Moons 0 0 1 0 2 79 82 27 14 5
Ring System? No No No No No Yes Yes Yes Yes No
Global Magnetic Field? Yes No Yes No No Yes Yes Yes Yes Unknown
NaN MERCURY VENUS EARTH MOON MARS JUPITER SATURN URANUS NEPTUNE PLUTO

After transposing, we must save it

We are saving it back to the same name

In [21]:
ss = ss.T
ss
Out[21]:
properties Mass Diameter Density Gravity Escape Velocity Rotation Period Length of Day Distance from Sun Perihelion Aphelion Orbital Period Orbital Velocity Orbital Eccentricity Obliquity to Orbit Surface Pressure Number of Moons Ring System? Global Magnetic Field? NaN
MERCURY 0.0553 0.383 0.984 0.378 0.384 58.8 175.9 0.387 0.313 0.459 0.241 1.59 12.3 0.001 0 0 No Yes MERCURY
VENUS 0.815 0.949 0.951 0.907 0.926 -244 116.8 0.723 0.731 0.716 0.615 1.18 0.401 0.113* 92 0 No No VENUS
EARTH 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 No Yes EARTH
MOON 0.0123 0.2724 0.605 0.166 0.213 27.4 29.5 0.00257* 0.00247* 0.00267* 0.0748* 0.0343* 3.29 0.285 0 0 No No MOON
MARS 0.107 0.532 0.713 0.377 0.450 1.03 1.03 1.52 1.41 1.64 1.88 0.808 5.60 1.07 0.01 2 No No MARS
JUPITER 317.8 11.21 0.240 2.36 5.32 0.415 0.414 5.20 5.03 5.37 11.9 0.439 2.93 0.134 Unknown* 79 Yes Yes JUPITER
SATURN 95.2 9.45 0.125 0.916 3.17 0.445 0.444 9.58 9.20 9.96 29.4 0.325 3.38 1.14 Unknown* 82 Yes Yes SATURN
URANUS 14.5 4.01 0.230 0.889 1.90 -0.720 0.718 19.20 18.64 19.75 83.7 0.228 2.74 4.17* Unknown* 27 Yes Yes URANUS
NEPTUNE 17.1 3.88 0.297 1.12 2.10 0.673 0.671 30.05 30.22 29.89 163.7 0.182 0.677 1.21 Unknown* 14 Yes Yes NEPTUNE
PLUTO 0.0025 0.186 0.380 0.071 0.116 6.41 6.39 39.48 30.16 48.49 247.9 0.157 14.6 2.45* 0.00001 5 No Unknown PLUTO

After transpose, reset the index

In [22]:
ss.index.names = ['name_of_planet']
ss
Out[22]:
properties Mass Diameter Density Gravity Escape Velocity Rotation Period Length of Day Distance from Sun Perihelion Aphelion Orbital Period Orbital Velocity Orbital Eccentricity Obliquity to Orbit Surface Pressure Number of Moons Ring System? Global Magnetic Field? NaN
name_of_planet
MERCURY 0.0553 0.383 0.984 0.378 0.384 58.8 175.9 0.387 0.313 0.459 0.241 1.59 12.3 0.001 0 0 No Yes MERCURY
VENUS 0.815 0.949 0.951 0.907 0.926 -244 116.8 0.723 0.731 0.716 0.615 1.18 0.401 0.113* 92 0 No No VENUS
EARTH 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 No Yes EARTH
MOON 0.0123 0.2724 0.605 0.166 0.213 27.4 29.5 0.00257* 0.00247* 0.00267* 0.0748* 0.0343* 3.29 0.285 0 0 No No MOON
MARS 0.107 0.532 0.713 0.377 0.450 1.03 1.03 1.52 1.41 1.64 1.88 0.808 5.60 1.07 0.01 2 No No MARS
JUPITER 317.8 11.21 0.240 2.36 5.32 0.415 0.414 5.20 5.03 5.37 11.9 0.439 2.93 0.134 Unknown* 79 Yes Yes JUPITER
SATURN 95.2 9.45 0.125 0.916 3.17 0.445 0.444 9.58 9.20 9.96 29.4 0.325 3.38 1.14 Unknown* 82 Yes Yes SATURN
URANUS 14.5 4.01 0.230 0.889 1.90 -0.720 0.718 19.20 18.64 19.75 83.7 0.228 2.74 4.17* Unknown* 27 Yes Yes URANUS
NEPTUNE 17.1 3.88 0.297 1.12 2.10 0.673 0.671 30.05 30.22 29.89 163.7 0.182 0.677 1.21 Unknown* 14 Yes Yes NEPTUNE
PLUTO 0.0025 0.186 0.380 0.071 0.116 6.41 6.39 39.48 30.16 48.49 247.9 0.157 14.6 2.45* 0.00001 5 No Unknown PLUTO

Check data type of each columns

A number data type is generally an int or a float.

Non-numeric data types are generally written as object.

In [23]:
ss.dtypes
Out[23]:
properties
Mass                      object
Diameter                  object
Density                   object
Gravity                   object
Escape Velocity           object
Rotation Period           object
Length of Day             object
Distance from Sun         object
Perihelion                object
Aphelion                  object
Orbital Period            object
Orbital Velocity          object
Orbital Eccentricity      object
Obliquity to Orbit        object
Surface Pressure          object
Number of Moons           object
Ring System?              object
Global Magnetic Field?    object
NaN                       object
dtype: object

We can convert a column's data type

In this case, we convert Mass to float data type.

A float is basically a decimal number.

In [24]:
ss.Gravity.astype(float)
Out[24]:
name_of_planet
MERCURY    0.378
VENUS      0.907
EARTH      1.000
MOON       0.166
MARS       0.377
JUPITER    2.360
SATURN     0.916
URANUS     0.889
NEPTUNE    1.120
PLUTO      0.071
Name: Gravity, dtype: float64

Plot the Mass

Only numeric columns can be plotted. So we converted it first as float.

See the mass of Jupiter, it is huge.

In [25]:
ss.Gravity.astype(float).plot()
Out[25]:
<AxesSubplot:xlabel='name_of_planet'>

We can plot in different types

This one is pie chart

We can see that Jupiter has almost three times the mass of all other planets put together.

In [26]:
ss.Gravity.astype(float).plot.pie()
Out[26]:
<AxesSubplot:ylabel='Gravity'>

A bar chart of Mass.

Note the towering mass of Jupyter

In [27]:
ss.Gravity.astype(float).plot.bar()
Out[27]:
<AxesSubplot:xlabel='name_of_planet'>

Log scale

In the above charts, we cannot see smaller planets. To fix it, we use log scale.

Add a new column log_mass

In [28]:
ss['log_Gravity'] = np.log(ss.Gravity.astype(float))

Check the last column

In [29]:
ss.columns
Out[29]:
Index([                  'Mass',               'Diameter',
                      'Density',                'Gravity',
              'Escape Velocity',        'Rotation Period',
                'Length of Day',      'Distance from Sun',
                   'Perihelion',               'Aphelion',
               'Orbital Period',       'Orbital Velocity',
         'Orbital Eccentricity',     'Obliquity to Orbit',
             'Surface Pressure',        'Number of Moons',
                 'Ring System?', 'Global Magnetic Field?',
                            nan,            'log_Gravity'],
      dtype='object', name='properties')
In [30]:
ss[['Gravity', 'log_Gravity']]
Out[30]:
properties Gravity log_Gravity
name_of_planet
MERCURY 0.378 -0.972861
VENUS 0.907 -0.097613
EARTH 1 0.000000
MOON 0.166 -1.795767
MARS 0.377 -0.975510
JUPITER 2.36 0.858662
SATURN 0.916 -0.087739
URANUS 0.889 -0.117658
NEPTUNE 1.12 0.113329
PLUTO 0.071 -2.645075

As the above data is comparison with the Earth, its value is 0. Smaller than the Earth are negative and others positive.

In [31]:
ss.log_Gravity.plot.bar()
Out[31]:
<AxesSubplot:xlabel='name_of_planet'>

Log data comparing with the smallest planet 'Pluto'

Please note that Pluto is no longer a planet now.

In [32]:
ss['log_Mass'] = np.log(ss.Mass.astype(float) / float(ss.Mass['PLUTO']))
In [33]:
ss[['Mass', 'log_Mass']]
Out[33]:
properties Mass log_Mass
name_of_planet
MERCURY 0.0553 3.096482
VENUS 0.815 5.786897
EARTH 1 5.991465
MOON 0.0123 1.593309
MARS 0.107 3.756538
JUPITER 317.8 11.752887
SATURN 95.2 10.547444
URANUS 14.5 8.665613
NEPTUNE 17.1 8.830543
PLUTO 0.0025 0.000000

Now all values are positive as they are larger than Pluto

In [34]:
ss.log_Mass.plot.bar()
Out[34]:
<AxesSubplot:xlabel='name_of_planet'>
Now the pie chart shows all planets, except Pluto
In [35]:
ss.log_Mass.plot.pie()
Out[35]:
<AxesSubplot:ylabel='log_Mass'>

Fix it by comparing all masses with half of the mass of Pluto

In [36]:
ss['log_Mass'] = np.log(ss.Mass.astype(float) / float(ss.Mass['PLUTO'])* 2 )
In [37]:
ss['log_Mass']
Out[37]:
name_of_planet
MERCURY     3.789629
VENUS       6.480045
EARTH       6.684612
MOON        2.286456
MARS        4.449685
JUPITER    12.446034
SATURN     11.240592
URANUS      9.358760
NEPTUNE     9.523690
PLUTO       0.693147
Name: log_Mass, dtype: float64
In [38]:
ss.log_Mass.plot.bar()
Out[38]:
<AxesSubplot:xlabel='name_of_planet'>
In [39]:
ss.log_Mass.plot.pie()
Out[39]:
<AxesSubplot:ylabel='log_Mass'>

Plot distance from Sun

In [40]:
ss["Distance from Sun"]
Out[40]:
name_of_planet
MERCURY       0.387
VENUS         0.723
EARTH             1
MOON       0.00257*
MARS           1.52
JUPITER        5.20
SATURN         9.58
URANUS        19.20
NEPTUNE       30.05
PLUTO         39.48
Name: Distance from Sun, dtype: object

Before we can plot, we have to remove * from the value of MOON

We convert first to str, then replace *

In [41]:
ss["Distance from Sun"] = ss["Distance from Sun"].str.replace('\*', '')
In [42]:
ss["Distance from Sun"]
Out[42]:
name_of_planet
MERCURY      0.387
VENUS        0.723
EARTH            1
MOON       0.00257
MARS          1.52
JUPITER       5.20
SATURN        9.58
URANUS       19.20
NEPTUNE      30.05
PLUTO        39.48
Name: Distance from Sun, dtype: object
In [43]:
ss["Distance from Sun"].astype(float).plot.pie()
Out[43]:
<AxesSubplot:ylabel='Distance from Sun'>

Remove unwanted or unavailable data

In 'Surface Pressure', we have some 'Unknown*' values. We will remove them to plot charts.

Let us first create a separate series of Surface Pressure only so that we don't change our original data.

In [44]:
ss_sp = ss["Surface Pressure"]
ss_sp
Out[44]:
name_of_planet
MERCURY           0
VENUS            92
EARTH             1
MOON              0
MARS           0.01
JUPITER    Unknown*
SATURN     Unknown*
URANUS     Unknown*
NEPTUNE    Unknown*
PLUTO       0.00001
Name: Surface Pressure, dtype: object

Use the following syntax to remove 'Unknown'

In [45]:
ss_sp = ss_sp[~ss_sp.str.contains("Unknown")]

All records with 'Unknown' are removed.

In [46]:
ss_sp
Out[46]:
name_of_planet
MERCURY          0
VENUS           92
EARTH            1
MOON             0
MARS          0.01
PLUTO      0.00001
Name: Surface Pressure, dtype: object
In [47]:
ss_sp.astype(float).plot.bar()
Out[47]:
<AxesSubplot:xlabel='name_of_planet'>
In [48]:
ss_sp.astype(float).plot.pie()
Out[48]:
<AxesSubplot:ylabel='Surface Pressure'>

Machine Learning

  1. Deal Banking Marketing Campaign Dataset With Machine Learning

TensorFlow

  1. Difference Between Scalar, Vector, Matrix and Tensor
  2. TensorFlow Deep Learning Model With IRIS Dataset
  3. Sequence to Sequence Learning With Neural Networks To Perform Number Addition
  4. Image Classification Model MobileNet V2 from TensorFlow Hub
  5. Step by Step Intent Recognition With BERT
  6. Sentiment Analysis for Hotel Reviews With NLTK and Keras
  7. Simple Sequence Prediction With LSTM
  8. Image Classification With ResNet50 Model
  9. Predict Amazon Inc Stock Price with Machine Learning
  10. Predict Diabetes With Machine Learning Algorithms
  11. TensorFlow Build Custom Convolutional Neural Network With MNIST Dataset
  12. Deal Banking Marketing Campaign Dataset With Machine Learning

PySpark

  1. How to Parallelize and Distribute Collection in PySpark
  2. Role of StringIndexer and Pipelines in PySpark ML Feature - Part 1
  3. Role of OneHotEncoder and Pipelines in PySpark ML Feature - Part 2
  4. Feature Transformer VectorAssembler in PySpark ML Feature - Part 3
  5. Logistic Regression in PySpark (ML Feature) with Breast Cancer Data Set

PyTorch

  1. Build the Neural Network with PyTorch
  2. Image Classification with PyTorch
  3. Twitter Sentiment Classification In PyTorch
  4. Training an Image Classifier in Pytorch

Natural Language Processing

  1. Spelling Correction Of The Text Data In Natural Language Processing
  2. Handling Text For Machine Learning
  3. Extracting Text From PDF File in Python Using PyPDF2
  4. How to Collect Data Using Twitter API V2 For Natural Language Processing
  5. Converting Text to Features in Natural Language Processing
  6. Extract A Noun Phrase For A Sentence In Natural Language Processing