Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. # In our class, Python ≥3.6 is required
  2. import sys
  3. assert sys.version_info >= (3, 6)
  4. # Scikit-Learn ≥0.21.3 is required
  5. import sklearn
  6. assert sklearn.__version__ >= "0.21.3"
  7. import matplotlib.pyplot as plt
  8. import pandas as pd
  9. import numpy as np
  10.  
  11. baseball = pd.read_csv("baseball.csv")
  12.  
  13. moneyball = baseball.loc[baseball["Year"] < 2002].copy()
  14.  
  15. #index = 1
  16. #lst = []
  17. #a = moneyball["Team"].unique()
  18. #print(a)
  19. #for el in a:
  20. #if el not in lst:
  21. #lst.append(index)
  22. #index += 1
  23. #print(lst) #wrong, useless
  24.  
  25. # Querini did this to give indexes
  26. team_idx = {v:k for [k, v] in list(enumerate(moneyball["Team"].unique()))}
  27. moneyball["id_team"] = [team_idx[x] for x in moneyball["Team"]]
  28.  
  29. col = np.where(moneyball["Playoffs"] == 1, "r", "k") #colours
  30. moneyball.plot(kind='scatter', c= col, x="W", y="id_team", )
  31. plt.tight_layout()
  32. plt.savefig('scatter-plot.png', dpi=600)
  33. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement