Advertisement
makispaiktis

Kaggle - Exercise 4 - Scatterplot, regplot, lmplot, swarmplot

Jul 2nd, 2023
1,059
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import pandas as pd
  2. pd.plotting.register_matplotlib_converters()
  3. import matplotlib.pyplot as plt
  4. # %matplotlib inline
  5. import seaborn as sns
  6.  
  7.  
  8. # 1. Read the dataset
  9. candy_filepath = "../input/candy.csv"
  10. candy_data = pd.read_csv(candy_filepath, index_col="id")
  11. print(candy_data.head())
  12.  
  13. # Which candy was more popular with survey respondents: '3 Musketeers' or 'Almond Joy'?
  14. more_popular = '3 Musketeers'
  15. # Which candy has higher sugar content: 'Air Heads' or 'Baby Ruth'?
  16. more_sugar = 'Air Heads'
  17.  
  18. # 2. Sugar vs Win ----> Scatter and regression line plot
  19. sns.scatterplot(x=candy_data['sugarpercent'], y=candy_data['winpercent'])
  20. sns.regplot(x=candy_data['sugarpercent'], y=candy_data['winpercent'])
  21.  
  22. # 3. Sugar vs Win vs Chocolate ----> Scatter and regression line plot (lmplot)
  23. sns.scatterplot(x=candy_data['pricepercent'], y=candy_data['winpercent'], hue=candy_data['chocolate'])
  24. sns.lmplot(data=candy_data, x="pricepercent", y="winpercent", hue="chocolate")
  25.  
  26. # 4. Chocolate vs Win
  27. sns.swarmplot(x=candy_data["chocolate"], y=candy_data["winpercent"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement