This is a project to determine the average diameter of planets in the solar system.

planets_diameter
In [1]:
# Average diameter of planets in the solar system.
In [2]:
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
In [3]:
# Reading the file.
data = pd.read_csv('planets.csv.txt', usecols= [0, 1, 2]) 
data
Out[3]:
planet mass diameter
0 Mercury 0.3300 4879
1 Venus 4.8700 12104
2 Earth 5.9700 12756
3 Mars 0.6420 6792
4 Jupiter 1898.0000 142984
5 Saturn 568.0000 120536
6 Uranus 86.8000 51118
7 Neptune 102.0000 49528
8 Pluto 0.0146 2370
In [4]:
# Extracting the information that we need.
diameters = np.array(data['diameter'])
planets = np.array(data['planet'])
print(planets)
print(diameters)
['Mercury' 'Venus' 'Earth' 'Mars' 'Jupiter' 'Saturn' 'Uranus' 'Neptune'
 'Pluto']
[  4879  12104  12756   6792 142984 120536  51118  49528   2370]
In [5]:
# Computing a variaty of summary statistics:
print("Mean diameter: ", diameters.mean())
print("Standard deviation:", diameters.std())
print("Minimum diameter: ", diameters.min())
print("Maximum diameter: ", diameters.max())
Mean diameter:  44785.22222222222
Standard deviation: 49858.41537299569
Minimum diameter:  2370
Maximum diameter:  142984
In [6]:
# In each case, the aggregation operation reduced the entire array to a single summarizing value, 
# giving the information about the distribution of values.
In [7]:
# Computing quantiles:
print("25th percentile: ", np.percentile(diameters, 25))
print("Median: ", np.median(diameters))
print("75th percentile: ", np.percentile(diameters, 75))
25th percentile:  6792.0
Median:  12756.0
75th percentile:  51118.0
In [8]:
# We can see that the median diameter of the planets in the solar system, is 12756.0 km(kilometers). 
In [9]:
# Visualizing the data:
In [10]:
import matplotlib.pyplot as plt
In [11]:
plt.style.use('fivethirtyeight') # Set the plot style.

plt.figure(figsize=(14, 8))
plt.hist(diameters)
plt.title('Diameter Distribution of planets in the solar system')
plt.xlabel('diameter (km)')
plt.ylabel('number')

plt.show()

Comments