This is a project to determine the average diameter of planets in the solar system.
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]:
In [4]:
# Extracting the information that we need.
diameters = np.array(data['diameter'])
planets = np.array(data['planet'])
print(planets)
print(diameters)
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())
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))
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
Post a Comment