-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
53 lines (36 loc) · 1.33 KB
/
test.py
File metadata and controls
53 lines (36 loc) · 1.33 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
import pandas as pd
import matplotlib.pyplot as plt
# read the document
data = pd.read_csv('raw_data.csv')
datas = pd.read_csv('raw_data.csv')
###draw the frequency distribution
bins = [48.3, 54.4, 60.4, 66.4, 72.4, 78.4, 84.4, 90.4]
labels = ['48.3-54.4', '54.4-60.4', '60.4-66.4', '66.4-72.4', '72.4-78.4', '78.4-84.4', '84.4-90.4']
data['Class'] = pd.cut(data['data'], bins, labels=labels)
data = pd.crosstab(index=data['Class'], columns='Frequency')
#print("\n Frequency distribution", data)
###draw the relative frequency distribution
data['RFD'] = data['Frequency']/105
# print("\n Relative frequency distribution", data)
###draw the cumulative frequency distribution
data['CFD'] = data['Frequency'].cumsum()
# print("\n Cumulative frequency distribution", data)
###draw the cumulative relative frequency distribution
data['CRFD'] = data['RFD'].cumsum()
#print("\n Cumulative relative frequency distribution", data)
###compute the mean
data['Mean'] = data.mean(True)
print("\n", data)
###compute the median
median = datas.median()
print("\n The median is", median)
###compute the mode
mode = datas.mode()
print("\n The mode is", mode)
n = data['CFD'].max()
#print((data['Mean'].cumsum())/n)
plt.hist(datas, bins, histtype='bar', color='red', align='mid')
plt.xlabel('Class')
plt.ylabel('Frequency')
plt.title('Histogram')
plt.show()