Python program that creates a planetary dataset for exoplanets, inspired by the image details of star types (A, B, F, G, K, M) and their characteristics:
```python
import pandas as pd
# Step 1: Define star and planet data
data = {
"StarType": ["A", "B", "F", "G", "K", "M"],
"Temperature_K": [10000, 15000, 7000, 5778, 4000, 3500],
"StellarRadius_SolarRadii": [2.0, 5.0, 1.3, 1.0, 0.7, 0.5],
"PlanetCount": [2, 1, 4, 8, 5, 3], # Number of exoplanets discovered
"AveragePlanetMass_JupiterMass": [3.0, 5.0, 0.8, 1.0, 0.5, 0.3],
"AverageOrbitPeriod_Days": [300, 800, 200, 365, 100, 50]
}
# Step 2: Create the dataset
exoplanet_df = pd.DataFrame(data)
# Step 3: Save the dataset to a CSV file
exoplanet_df.to_csv("exoplanet_dataset.csv", index=False)
# Step 4: Display the dataset
print("Exoplanet Dataset:")
print(exoplanet_df)
```
### Dataset Description:
This program generates a dataset with the following columns:
- StarType: The type of star (A, B, F, G, K, M).
- Temperature_K: The average surface temperature of the star (Kelvin).
- StellarRadius_SolarRadii: The radius of the star in solar radii (relative to the sun's radius).
- PlanetCount: Number of exoplanets orbiting each star type.
- AveragePlanetMass_JupiterMass: Average mass of the planets (in Jupiter masses).
- AverageOrbitPeriod_Days: Average orbital period of planets (in Earth days).
### How It Works:
1. Creates a Python dictionary containing star and planet data.
2. Converts the dictionary into a Pandas DataFrame.
3. Saves the dataset as a CSV file (`exoplanet_dataset.csv`) for further analysis.
4. Prints the dataset for immediate viewing. π
# Import necessary libraries
import pandas as pd
import matplotlib.pyplot as plt
# Step 1: Load the dataset
# Replace 'exoplanet_data.csv' with the path to your dataset
try:
data = pd.read_csv('exoplanet_data.csv')
except FileNotFoundError:
print("Dataset not found. Please ensure 'exoplanet_data.csv' is in the same directory.")
exit()
# Step 2: Explore the dataset
print(data.head()) # Display the first 5 rows of the dataset
print(data.info()) # Show information about the columns
# Step 3: Filter relevant columns (e.g., Star Type, Planet Mass, Orbit Period)
relevant_columns = ['StarType', 'PlanetMass', 'OrbitPeriod']
data = data[relevant_columns]
# Step 4: Data cleaning (remove rows with missing values)
data.dropna(inplace=True)
# Step 5: Visualize the data
# Scatter plot: Planet Mass vs Orbit Period
plt.figure(figsize=(10, 6))
scatter = plt.scatter(data['OrbitPeriod'], data['PlanetMass'], c=data['StarType'].astype('category').cat.codes, cmap='viridis')
plt.colorbar(scatter, label='Star Type (Encoded)')
plt.xlabel('Orbit Period (days)')
plt.ylabel('Planet Mass (Jupiter Mass)')
plt.title('Exoplanet Characteristics by Star Type')
plt.grid()
plt.show()
# Step 6: Basic Statistics
print("\nBasic Statistics:")
print(data.describe())
# Step 7: Grouping data by star type
grouped_data = data.groupby('StarType').mean()
print("\nAverage Planet Mass and Orbit Period by Star Type:")
print(grouped_data)


No comments:
Post a Comment