-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
70 lines (48 loc) · 2.71 KB
/
Copy pathapp.py
File metadata and controls
70 lines (48 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
df_vehicles = pd.read_csv('vehicles_us.csv')
st.header("Explore the Raw Data", divider = True)
st.write("Raw DataFrame:", df_vehicles)
# Check for Duplicated Values and null values
vehicle_duplicates = df_vehicles[df_vehicles.duplicated]
#Truncate the values for the model column to include just the maker of the car.
# This provides a simplifed view; all models for each maker would make an extremely large amount of values on the respective axis
df_vehicles['model'] = df_vehicles['model'].apply(lambda x: x.split()[0])
print(df_vehicles['model'])
#Remove outliers from data
df_vehicles['price'] = df_vehicles['price'][df_vehicles['price'] < 30000]
df_vehicles['model_year'] = df_vehicles['model_year'][df_vehicles['model_year'] > 1980]
df_vehicles['odometer'] = df_vehicles['odometer'][df_vehicles['odometer'] < 400000]
df_vehicles['days_listed'] = df_vehicles['days_listed'][df_vehicles['days_listed'] < 120]
#Empty dataframe is returned, therefore there are no duplicates
#In the model_year column, we have null values. Without these values, we cannot accurately assess a cars values, as there are notable differences between years
#These empty columns will be changed the median per model
#Use transform function to add the median model year for each model to null values
model_median = df_vehicles.groupby('model')['model_year'].median()
df_vehicles['model_year'] = df_vehicles.groupby('model')['model_year'].transform(lambda x: x.fillna(model_median[x.name]))
odometer_mean = df_vehicles.groupby('model')['odometer'].mean()
df_vehicles['odometer'] = df_vehicles.groupby('model')['odometer'].transform(lambda x: x.fillna(odometer_mean[x.name]))
cylinders_median = df_vehicles.groupby('model')['cylinders'].median()
df_vehicles['cylinders'] = df_vehicles.groupby('model')['cylinders'].transform(lambda x: x.fillna(cylinders_median[x.name]))
#Check to see if the null values have been filled
df2 = df_vehicles['model_year'][df_vehicles['model_year'].isna()]
df3 = df_vehicles['odometer'][df_vehicles['odometer'].isna()]
df4 = df_vehicles['cylinders'][df_vehicles['cylinders'].isna()]
""" """
show_hist = st.checkbox("Show Histogram")
show_scatterplot = st.checkbox("Show Scatterplot")
if show_hist:
#Here is the histogram showing the amount of days listed per vehicle type:
st.header(":blue[Histogram] Plot of Type vs Days Listed")
fig = px.histogram(
df_vehicles,
x = 'days_listed',
color = 'type'
)
st.plotly_chart(fig)
if show_scatterplot:
st.header(":green[Scatterplot] Plot of Type vs Days Listed")
fig1 = px.scatter(df_vehicles, x="model_year", y="odometer", color='price')
st.plotly_chart(fig1)