-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMckinsey.py
93 lines (72 loc) · 1.74 KB
/
Mckinsey.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import numpy.matlib
import numpy as np
a = np.array([[1,2],[3,4]])
#print(a)
b = np.array([[11,12],[13,14]])
#print(b)
# creating numpy array
arr = np.array([[1, 2, 3, 4, 5],
[np.nan, 4, np.nan, 2, 1],
[np.nan, 2, 4, 1, 5],
[3, 4, 3, 2, 1]])
indexList = np.isnan(arr).any(axis=1)
print(np.isnan(arr))
'''
[[False False False False False]
[ True False True False False]
[ True False False False False]
[False False False False False]]
'''
#print(indexList)
# -> Outptu: [False, True, True, False]
# remove row with missing value
arr = np.delete(arr, indexList, axis=0)
print(arr)
'''
[[1. 2. 3. 4. 5.]
[3. 4. 3. 2. 1.]]
'''
# remove column with missing value
# creating numpy array
arr1 = np.array([[1, 2, 3, 4, 5],
[np.nan, 4, np.nan, 2, 1],
[np.nan, 2, 4, 1, 5],
[3, 4, 3, 2, 1]])
# Get an index of columns which has any NaN value
index1 = np.isnan(arr1).any(axis=0)
# Delete columns with any NaN value from 2D NumPy Array
arr1 = np.delete(arr1, index1, axis=1)
print(arr1)
###########################
import pandas as pd
df = pd.DataFrame({'A': [1, np.nan, 2, 6], 'B': [5, np.nan, 8, 2]})
'''
array([[ 1., 5.],
[nan, nan],
[ 2., 8.],
[ 6., 2.]])
'''
m = df.to_numpy()
#print(m)
mean = np.nanmean(m, axis = 0)
idx = np.where(np.isnan(m))
print(idx)
m[idx] = np.take(mean, idx[1])
print(m)
'''
array([[1., 5.],
[3., 5.],
[2., 8.],
[6., 2.]])
'''
def flag(arr, thr):
solution = np.empty()
for i in range(0,len(arr)):
if arr[i]<thr:
solution[i]=0
else:
solution[i]=1
return solution
test_arr = np.array([[65],[233],[330]])
case = flag(test_arr,300)
print(case)