Skip to content
Toyota Sales
Unknown table
DataFrameas
toyota
variable
-- Explore the data in the table
SELECT *
FROM 'toyota.csv'import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plttoyota.head()toyota['year'] = toyota['year'].astype(int)
toyota['model'] = toyota['model'].astype("string").str.strip()
toyota['price'] = toyota['price'].astype(int)
toyota['transmission'] = toyota['transmission'].astype("string").str.strip()
toyota['mileage'] = toyota['mileage'].astype(int)
toyota['fuelType'] = toyota['fuelType'].astype("string").str.strip()
toyota['tax'] = toyota['tax'].astype(int)
toyota['mpg'] = toyota['mpg'].astype(float)
toyota['engineSize'] = toyotaa['engineSize'].astype(int)
toyota.info()Hidden code
Hidden code
Hidden code
petrol_counts = toyota.loc[toyota['fuelType'] == 'Hybrid']['model']\
.value_counts().head(5)
petrol_sort = petrol_counts.index
sns.countplot(
x='model',
data=toyota[toyota['fuelType'] == 'Hybrid'],
order=petrol_sort,
color="#d9d9d9ff"
)
plt.gca().spines["top"].set_visible(False)
plt.gca().spines["right"].set_visible(False)
plt.gca().spines["left"].set_visible(False)
plt.gca().spines["bottom"].set_visible(False)
plt.xlabel("Car Model")
plt.ylabel("Count Sold")
plt.title("Sales Count of Hybrid Cars only by Model")
plt.xticks(rotation=45)
plt.show()Hidden code
toyota.mpg.max()toyota.mpg.min()#Create bins for MPG Category
bins = [0, 20, 40, 60, 80, 100,
120, 140, 160, 180,
200, 220, 235]
labels = ["1-20", "21-40", "41-60", "61-80", "81-100",
"101-120", "121-140", "141-160", "161-180",
"181-200", "201-220", "221-235"]
toyota["MPG Category"] = pd.cut(toyota["mpg"], bins=bins, labels=labels, right=True)sns.histplot(
x=toyota["MPG Category"],
discrete=True,
color='#d9d9d9ff'
)
plt.gca().spines["top"].set_visible(False)
plt.gca().spines["right"].set_visible(False)
plt.gca().spines["left"].set_visible(False)
plt.gca().spines["bottom"].set_visible(False)
plt.grid(True, axis="y", linestyle="--", alpha=0.3)
plt.xticks(rotation=45)
plt.xlabel("MPG Category")
plt.ylabel("Counts")
plt.title("MPG Category Distribution")
plt.show()