Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import numpy as np
- import pandas as pd
- from sklearn.preprocessing import minmax_scale
- import numpy as np
- import pandas as pd
- import seaborn as sns
- import matplotlib.pyplot as plt
- '''
- Take a list and create the formatted matrix
- '''
- def mkdf(ListOf480Numbers):
- normalMatrix = np.array_split(ListOf480Numbers,8) #Take a list and create 8 array (Sections)
- fixMatrix = []
- for i in range(8):
- lines = np.array_split(normalMatrix[i],6) #Split each section in lines (each line contains 10 cells from 0-9)
- newMatrix = [0,0,0,0,0,0] #empty array to contain reordered lines
- for j in (0,2,4):
- newMatrix[j] = lines[j] #lines 1,3,5 remain equal
- for j in (1,3,5):
- newMatrix[j] = lines[j][::-1] #lines 2,4,6 are inverted
- fixMatrix.append(newMatrix)
- return fixMatrix
- '''
- Print the matrix with the required format
- '''
- def print_df(fixMatrix, csv):
- f = open(csv,"w")
- printMatrix = []
- for i in range(6):
- printMatrix.append(np.concatenate([fixMatrix[4][i],fixMatrix[7][i]])) #lines form section 4 and 7 are side by side
- for i in range(6):
- printMatrix.append(np.concatenate([fixMatrix[5][i],fixMatrix[6][i]])) #lines form section 5 and 6 are side by side
- for i in range(6):
- printMatrix.append(np.concatenate([fixMatrix[1][i],fixMatrix[2][i]])) #lines form section 1 and 2 are side by side
- for i in range(6):
- printMatrix.append(np.concatenate([fixMatrix[0][i],fixMatrix[3][i]])) #lines form section 0 and 3 are side by side
- for i in printMatrix:
- i = np.array(i,dtype='U20')
- f.write(",".join(i) + "\n")
- f.close()
- f = open("D:\me4.txt")
- me4 = f.readlines()
- f.close()
- speed = []
- acceleration = []
- temperature = []
- '''
- Remove "\n caracter"
- '''
- for i in range(len(me4)):
- me4[i] = me4[i].rstrip("\n")
- '''
- Split data in three diferent lists speed, acceleration and temperature
- '''
- for i in range(0,len(me4)-3,4):
- speed.append(me4[i+1])
- acceleration.append(me4[i+2])
- temperature.append(me4[i+3])
- '''
- Print each matrix
- '''
- print("Speed\n====Done")
- SpeedMatrix = mkdf(speed) #see definition of the function
- print_df(SpeedMatrix, "speed.csv") #see definition of the function
- print("Acceleration\n====Done")
- AccMatrix = mkdf(acceleration) #see definition of the function
- print_df(AccMatrix, "acceleration.csv") #see definition of the function
- print("Temperature\n====Done")
- newTemp = np.array(temperature, dtype='float64')
- newTemp_norm = minmax_scale(newTemp, feature_range=(-40, 150))
- TempMatrix = mkdf(newTemp_norm) #see definition of the function
- print_df(TempMatrix, "temperature.csv") #see definition of the function
- '''
- Missing data plot
- '''
- speed_df = pd.read_csv("speed.csv",header=None)
- speed_df = speed_df.replace(0,np.nan)
- sns.heatmap(speed_df.isnull(),cbar=False)
- c = 0
- for i in nan:
- for j in i:
- if j:
- c += 1
- print (f'Null values equals {c}')
- plt.show()
- speed = np.array(speed, dtype='float64')
- acceleration = np.array(acceleration, dtype='float64')
- temperature = np.array(temperature, dtype='float64')
- df = pd.DataFrame({"Speed":speed,"Acceleration":acceleration,"Temperature":temperature})
- df = df.replace(0,np.nan)
- sns.heatmap(df.isnull(),cbar=False)
- nan = np.array(df.isnull())
- c = 0
- for i in nan:
- for j in i:
- if j:
- c += 1
- print (f'Null values equals {c}')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement