-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarchart
73 lines (48 loc) · 2.06 KB
/
barchart
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
71
72
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use("fivethirtyeight")
xls = pd.ExcelFile('STAT.xlsx')
novak = pd.read_excel(xls, 'DJOKOVIC')
def get_w_l(df):
SINGLES_W = []
SINGLES_L = []
for i in df['SINGLES W-L']:
SINGLES_W.append(int(i.split("-")[0]))
SINGLES_L.append(int(i.split("-")[1]))
return SINGLES_W, SINGLES_L
novak = novak.iloc[:-1,]
novak['SINGLES_W'], novak['SINGLES_L'] = get_w_l(novak)
novak.drop(['SINGLES W-L'], axis = 1, inplace=True)
novak.set_index('YEAR', inplace = True)
novak.index = pd.to_datetime(novak.index, format = "%Y")
novak.index = novak.index.year
#novak = pd.to_numeric(novak, errors = "coerce")
novak = novak.astype('int')
novak = novak[::-1]
federer = pd.read_excel(xls, 'FEDERER')
federer = federer.iloc[:-1,]
federer['SINGLES_W'], federer['SINGLES_L'] = get_w_l(federer)
federer.drop(['SINGLES W-L'], axis = 1, inplace=True)
federer.set_index('YEAR', inplace = True)
federer.index = pd.to_datetime(federer.index, format = "%Y").year
federer = federer.astype('int')
federer = federer[::-1]
nadal = pd.read_excel(xls, 'NADAL')
nadal = nadal.iloc[:-1,]
nadal['SINGLES_W'], nadal['SINGLES_L'] = get_w_l(nadal)
nadal.drop(['SINGLES W-L'], axis = 1, inplace=True)
nadal.set_index('YEAR', inplace = True)
nadal.index = pd.to_datetime(nadal.index, format = "%Y").year
nadal = nadal.astype('int')
nadal = nadal[::-1]
nishikori = pd.read_excel(xls, 'NISHIKORI')
nishikori = nishikori.iloc[:-1,]
nishikori['SINGLES_W'], nishikori['SINGLES_L'] = get_w_l(nishikori)
nishikori.drop(['SINGLES W-L'], axis = 1, inplace=True)
nishikori.set_index('YEAR', inplace = True)
nishikori.index = pd.to_datetime(nishikori.index, format = "%Y").year
nishikori = nishikori.astype('int')
nishikori = nishikori[::-1]
df = pd.concat([novak[['SINGLES TITLES']], federer[['SINGLES TITLES']], nadal[['SINGLES TITLES']], nishikori[['SINGLES TITLES']]], axis =1)
df.columns = ['Djokovic', 'Federer', 'Nadal', 'Nishikori']
df.plot(kind='bar', figsize = (15, 8), title="SINGLES TITLES OF DJOKOVIC AND HIS OPPONENTS FROM 2007-2019")