Advertisement
tuomasvaltanen

Untitled

Apr 13th, 2021 (edited)
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. # data analysis workshop 1, 13.4.2021
  2.  
  3. # example, car sales
  4.  
  5. import numpy as np
  6. import pandas as pd
  7. import seaborn as sns
  8. import matplotlib.pyplot as plt
  9. from scipy import stats
  10.  
  11. def percentage_difference(row):
  12.     selling = row['Selling_Price']
  13.     road = row['Present_Price']
  14.     result = 1 - round(selling / road, 2)
  15.     return result
  16.  
  17.  
  18. cars = pd.read_csv('car data.csv')
  19.  
  20. cars = cars.drop('Car_Name', axis=1)
  21.  
  22. cars['Price_Difference'] = cars.apply(percentage_difference, axis=1)
  23.  
  24. column_names = ['Year', 'Selling_Price', 'Present_Price', 'Price_Difference', 'Kms_Driven', 'Fuel_Type', 'Seller_Type', 'Transmission', 'Owner']
  25. cars = cars.reindex(columns=column_names)
  26.  
  27. cars = cars.drop('Owner', axis=1)
  28.  
  29. automatic_diesels = cars[cars['Fuel_Type'] == 'Diesel']
  30.  
  31. # the amount of extra costs (price difference) is affected by car year and kms driven
  32. correlations = cars.corr()
  33.  
  34. plt.clf()
  35. sns.pairplot(cars)
  36. plt.figure()
  37.  
  38.  
  39. # Automatic transmission cars tend to be more expensive
  40. plt.clf()
  41. sns.pairplot(cars, hue='Transmission')
  42. plt.figure()
  43.  
  44. # Also Diesel fuel type seem to be more valuable in used cars
  45. plt.clf()
  46. sns.pairplot(cars, hue='Fuel_Type')
  47. plt.figure()
  48.  
  49. plt.clf()
  50. sns.boxplot(x='Transmission', y='Present_Price', data=cars, hue='Fuel_Type')
  51. plt.figure()
  52.  
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement