TypeError during getting Heatmap plot for missing data includes inf
I wrote codes to demonstrate values of 3 parameters[Speed, Acceleration, Temperature] from my dataset(text file) via HeatMap plots in 24x20 matrices form. Data in text file were saved in this order:
Pointer-Speed-Acceleration-Temperature
and repeated many times and after 480times repeated again as 2nd cycle and so on.
So I extracted these main parameters and put them in lists and for each parameter in each cycle I print and save csv file and try to plot each values and also try to plot missing values(includes nan and inf) for every parameter and try to get all plots in one window with title of right cycle number and try to count missing values(not only nan but also inf) to mention next plots during getting plot for them via insnull and replacing missing values by 0 ( I prefer Nan and Inf replaced by last available value in previous cycle or in the best case replace by mean of values of last and next available cycles instead of 0 )but I've faced below error:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
I'm wondering if there's a elegant way to count inf and nan separately in lists and print them out in plot window via HeatMap and isnull for each cycle including counting info and save them somewhere in hard disk for other tasks.
My scripts are following:
import sys
import os
import numpy as np
import pandas as pd
#from sklearn.preprocessing import minmax_scale
import seaborn as sns
import matplotlib.pyplot as plt
def mkdf(ListOf480Numbers):
normalMatrix = np.array_split(ListOf480Numbers,8)
fixMatrix =
for i in range(8):
lines = np.array_split(normalMatrix[i],6)
newMatrix = [0,0,0,0,0,0]
for j in (1,3,5):
newMatrix[j] = lines[j]
for j in (0,2,4):
newMatrix[j] = lines[j][::-1]
fixMatrix.append(newMatrix)
return fixMatrix
def print_df(fixMatrix):
values =
for i in range(6):
values.append([*fixMatrix[6][i], *fixMatrix[7][i]])
for i in range(6):
values.append([*fixMatrix[4][i], *fixMatrix[5][i]])
for i in range(6):
values.append([*fixMatrix[2][i], *fixMatrix[3][i]])
for i in range(6):
values.append([*fixMatrix[0][i], *fixMatrix[1][i]])
df = pd.DataFrame(values)
return (df)
df = pd.read_csv('D:me4.TXT', header=None)
id_set = df[df.index % 4 == 0].astype('int').values
Speed = df[df.index % 4 == 1].values
Acceleration = df[df.index % 4 == 2].values
Temperature = df[df.index % 4 == 3].values
data = {'Speed': Speed[:,0], 'Acceleration': Acceleration[:,0], 'Temperature': Temperature[:,0]}
main_data = pd.DataFrame(data, columns=['Speed','Acceleration','Temperature'], index = id_set[:,0])
def plotheatmap(new_value):
Sections = mkdf(new_value)
df = print_df(Sections)
sns.heatmap(df, vmin=min_nor, vmax=max_nor, cmap ='coolwarm')
plt.title(i, fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.savefig(f'{i}/{i}{count}.png')
plt.clf()
return
'''
Missing data plot
'''
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]})
#pd.isnull(np.array([np.nan, 0], dtype=object))
pd.isnull(np.array([np.nan, 0], dtype=float))
df = df.replace(0,np.nan)
df = df.replace(1,np.inf)
plt.subplot2grid((3, 3), (2, 0), colspan=3)
plt.suptitle('Analysis of data in cycle Nr.{count}', fontsize=14, fontweight='bold')
plt.subplots_adjust(hspace=0.5, bottom=0.1)
sns.heatmap(df.isnull(),cbar=False)
plt.text(3, 4, r'nan={c} inf={d}',
verticalalignment='bottom', horizontalalignment='right', color='green', fontsize=15)
nan = np.array(df.isnull())
inf = np.array(df.isnull())
count_nan = len(df) - df.count()
print(count_nan)
c = 0
for i in nan:
for j in i:
if j:
c += 1
print(f'Total nan: {c}')
d = 1
for i in inf:
for j in i:
if j:
d += 1
print(f'Total inf: {d}')
plt.title(f'Total missing values: {c+d}', fontsize=12, color='black',
loc='left', style='italic')
plt.axis('off')
cycles = int(len(main_data)/480)
print(f'Total cycles: {cycles}')
for i in main_data:
for cycle in range(3):
count = '{:04}'.format(cycle)
j = cycle * 480
ordered_data = mkdf(main_data.iloc[j:j+480][i])
csv = print_df(ordered_data)
csv.to_csv(f'{i}{count}.csv', header=None, index=None)
Sections = mkdf(ordered_data)
df = print_df(Sections)
plt.title(i, fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.savefig(f'{i}{count}.png')
plt.clf()
'''
Speed plot
'''
Speed_df = pd.read_csv("Speed.csv",header=None)
plt.subplot2grid((3, 3), (0, 0), colspan=1)
sns.heatmap(Speed_df, vmin=-1, vmax=1, cmap ="coolwarm")
plt.title('Speed', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Speed missing plot
'''
Speed_df = pd.read_csv("Speed.csv",header=None)
Speed_df = Speed_df.replace(0,np.nan)
plt.subplot2grid((3, 3), (1, 0), colspan=1)
sns.heatmap(Speed_df.isnull(),cbar=False)
plt.title(f'Speed MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
acceleration plot
'''
acc_df = pd.read_csv("acceleration.csv",header=None)
plt.subplot2grid((3, 3), (0, 1), colspan=1)
sns.heatmap(acc_df, vmin=-1, vmax=1, cmap ="coolwarm")
plt.title('acceleration', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
acceleration missing plot
'''
acceleration_df = pd.read_csv("acceleration.csv",header=None)
acceleratione_df = acceleration_df.replace(0,np.nan)
plt.subplot2grid((3, 3), (1, 1), colspan=1)
sns.heatmap(acceleration_df.isnull(),cbar=False)
plt.title(f'accel MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Temperature plot
'''
temp_df = pd.read_csv("temperature.csv",header=None)
plt.subplot2grid((3, 3), (0, 2), colspan=1)
sns.heatmap(temp_df, vmin=-40, vmax=150, cmap ="coolwarm")
plt.title('Temperature', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Temperature missing plot
'''
temperature_df = pd.read_csv("temperature.csv",header=None)
temperature_df = temperature_df.replace(0,np.nan)
temperature_df = temperature_df.replace(0,np.inf)
plt.subplot2grid((3, 3), (1, 2), colspan=1)
sns.heatmap(temperature_df.isnull(),cbar=False)
plt.title(f'temp MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.show()
My desired result is:

I also provide sample text file of dataset for 3 cycles:
dataset
python dataframe typeerror seaborn missing-data
add a comment |
I wrote codes to demonstrate values of 3 parameters[Speed, Acceleration, Temperature] from my dataset(text file) via HeatMap plots in 24x20 matrices form. Data in text file were saved in this order:
Pointer-Speed-Acceleration-Temperature
and repeated many times and after 480times repeated again as 2nd cycle and so on.
So I extracted these main parameters and put them in lists and for each parameter in each cycle I print and save csv file and try to plot each values and also try to plot missing values(includes nan and inf) for every parameter and try to get all plots in one window with title of right cycle number and try to count missing values(not only nan but also inf) to mention next plots during getting plot for them via insnull and replacing missing values by 0 ( I prefer Nan and Inf replaced by last available value in previous cycle or in the best case replace by mean of values of last and next available cycles instead of 0 )but I've faced below error:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
I'm wondering if there's a elegant way to count inf and nan separately in lists and print them out in plot window via HeatMap and isnull for each cycle including counting info and save them somewhere in hard disk for other tasks.
My scripts are following:
import sys
import os
import numpy as np
import pandas as pd
#from sklearn.preprocessing import minmax_scale
import seaborn as sns
import matplotlib.pyplot as plt
def mkdf(ListOf480Numbers):
normalMatrix = np.array_split(ListOf480Numbers,8)
fixMatrix =
for i in range(8):
lines = np.array_split(normalMatrix[i],6)
newMatrix = [0,0,0,0,0,0]
for j in (1,3,5):
newMatrix[j] = lines[j]
for j in (0,2,4):
newMatrix[j] = lines[j][::-1]
fixMatrix.append(newMatrix)
return fixMatrix
def print_df(fixMatrix):
values =
for i in range(6):
values.append([*fixMatrix[6][i], *fixMatrix[7][i]])
for i in range(6):
values.append([*fixMatrix[4][i], *fixMatrix[5][i]])
for i in range(6):
values.append([*fixMatrix[2][i], *fixMatrix[3][i]])
for i in range(6):
values.append([*fixMatrix[0][i], *fixMatrix[1][i]])
df = pd.DataFrame(values)
return (df)
df = pd.read_csv('D:me4.TXT', header=None)
id_set = df[df.index % 4 == 0].astype('int').values
Speed = df[df.index % 4 == 1].values
Acceleration = df[df.index % 4 == 2].values
Temperature = df[df.index % 4 == 3].values
data = {'Speed': Speed[:,0], 'Acceleration': Acceleration[:,0], 'Temperature': Temperature[:,0]}
main_data = pd.DataFrame(data, columns=['Speed','Acceleration','Temperature'], index = id_set[:,0])
def plotheatmap(new_value):
Sections = mkdf(new_value)
df = print_df(Sections)
sns.heatmap(df, vmin=min_nor, vmax=max_nor, cmap ='coolwarm')
plt.title(i, fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.savefig(f'{i}/{i}{count}.png')
plt.clf()
return
'''
Missing data plot
'''
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]})
#pd.isnull(np.array([np.nan, 0], dtype=object))
pd.isnull(np.array([np.nan, 0], dtype=float))
df = df.replace(0,np.nan)
df = df.replace(1,np.inf)
plt.subplot2grid((3, 3), (2, 0), colspan=3)
plt.suptitle('Analysis of data in cycle Nr.{count}', fontsize=14, fontweight='bold')
plt.subplots_adjust(hspace=0.5, bottom=0.1)
sns.heatmap(df.isnull(),cbar=False)
plt.text(3, 4, r'nan={c} inf={d}',
verticalalignment='bottom', horizontalalignment='right', color='green', fontsize=15)
nan = np.array(df.isnull())
inf = np.array(df.isnull())
count_nan = len(df) - df.count()
print(count_nan)
c = 0
for i in nan:
for j in i:
if j:
c += 1
print(f'Total nan: {c}')
d = 1
for i in inf:
for j in i:
if j:
d += 1
print(f'Total inf: {d}')
plt.title(f'Total missing values: {c+d}', fontsize=12, color='black',
loc='left', style='italic')
plt.axis('off')
cycles = int(len(main_data)/480)
print(f'Total cycles: {cycles}')
for i in main_data:
for cycle in range(3):
count = '{:04}'.format(cycle)
j = cycle * 480
ordered_data = mkdf(main_data.iloc[j:j+480][i])
csv = print_df(ordered_data)
csv.to_csv(f'{i}{count}.csv', header=None, index=None)
Sections = mkdf(ordered_data)
df = print_df(Sections)
plt.title(i, fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.savefig(f'{i}{count}.png')
plt.clf()
'''
Speed plot
'''
Speed_df = pd.read_csv("Speed.csv",header=None)
plt.subplot2grid((3, 3), (0, 0), colspan=1)
sns.heatmap(Speed_df, vmin=-1, vmax=1, cmap ="coolwarm")
plt.title('Speed', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Speed missing plot
'''
Speed_df = pd.read_csv("Speed.csv",header=None)
Speed_df = Speed_df.replace(0,np.nan)
plt.subplot2grid((3, 3), (1, 0), colspan=1)
sns.heatmap(Speed_df.isnull(),cbar=False)
plt.title(f'Speed MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
acceleration plot
'''
acc_df = pd.read_csv("acceleration.csv",header=None)
plt.subplot2grid((3, 3), (0, 1), colspan=1)
sns.heatmap(acc_df, vmin=-1, vmax=1, cmap ="coolwarm")
plt.title('acceleration', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
acceleration missing plot
'''
acceleration_df = pd.read_csv("acceleration.csv",header=None)
acceleratione_df = acceleration_df.replace(0,np.nan)
plt.subplot2grid((3, 3), (1, 1), colspan=1)
sns.heatmap(acceleration_df.isnull(),cbar=False)
plt.title(f'accel MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Temperature plot
'''
temp_df = pd.read_csv("temperature.csv",header=None)
plt.subplot2grid((3, 3), (0, 2), colspan=1)
sns.heatmap(temp_df, vmin=-40, vmax=150, cmap ="coolwarm")
plt.title('Temperature', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Temperature missing plot
'''
temperature_df = pd.read_csv("temperature.csv",header=None)
temperature_df = temperature_df.replace(0,np.nan)
temperature_df = temperature_df.replace(0,np.inf)
plt.subplot2grid((3, 3), (1, 2), colspan=1)
sns.heatmap(temperature_df.isnull(),cbar=False)
plt.title(f'temp MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.show()
My desired result is:

I also provide sample text file of dataset for 3 cycles:
dataset
python dataframe typeerror seaborn missing-data
add a comment |
I wrote codes to demonstrate values of 3 parameters[Speed, Acceleration, Temperature] from my dataset(text file) via HeatMap plots in 24x20 matrices form. Data in text file were saved in this order:
Pointer-Speed-Acceleration-Temperature
and repeated many times and after 480times repeated again as 2nd cycle and so on.
So I extracted these main parameters and put them in lists and for each parameter in each cycle I print and save csv file and try to plot each values and also try to plot missing values(includes nan and inf) for every parameter and try to get all plots in one window with title of right cycle number and try to count missing values(not only nan but also inf) to mention next plots during getting plot for them via insnull and replacing missing values by 0 ( I prefer Nan and Inf replaced by last available value in previous cycle or in the best case replace by mean of values of last and next available cycles instead of 0 )but I've faced below error:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
I'm wondering if there's a elegant way to count inf and nan separately in lists and print them out in plot window via HeatMap and isnull for each cycle including counting info and save them somewhere in hard disk for other tasks.
My scripts are following:
import sys
import os
import numpy as np
import pandas as pd
#from sklearn.preprocessing import minmax_scale
import seaborn as sns
import matplotlib.pyplot as plt
def mkdf(ListOf480Numbers):
normalMatrix = np.array_split(ListOf480Numbers,8)
fixMatrix =
for i in range(8):
lines = np.array_split(normalMatrix[i],6)
newMatrix = [0,0,0,0,0,0]
for j in (1,3,5):
newMatrix[j] = lines[j]
for j in (0,2,4):
newMatrix[j] = lines[j][::-1]
fixMatrix.append(newMatrix)
return fixMatrix
def print_df(fixMatrix):
values =
for i in range(6):
values.append([*fixMatrix[6][i], *fixMatrix[7][i]])
for i in range(6):
values.append([*fixMatrix[4][i], *fixMatrix[5][i]])
for i in range(6):
values.append([*fixMatrix[2][i], *fixMatrix[3][i]])
for i in range(6):
values.append([*fixMatrix[0][i], *fixMatrix[1][i]])
df = pd.DataFrame(values)
return (df)
df = pd.read_csv('D:me4.TXT', header=None)
id_set = df[df.index % 4 == 0].astype('int').values
Speed = df[df.index % 4 == 1].values
Acceleration = df[df.index % 4 == 2].values
Temperature = df[df.index % 4 == 3].values
data = {'Speed': Speed[:,0], 'Acceleration': Acceleration[:,0], 'Temperature': Temperature[:,0]}
main_data = pd.DataFrame(data, columns=['Speed','Acceleration','Temperature'], index = id_set[:,0])
def plotheatmap(new_value):
Sections = mkdf(new_value)
df = print_df(Sections)
sns.heatmap(df, vmin=min_nor, vmax=max_nor, cmap ='coolwarm')
plt.title(i, fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.savefig(f'{i}/{i}{count}.png')
plt.clf()
return
'''
Missing data plot
'''
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]})
#pd.isnull(np.array([np.nan, 0], dtype=object))
pd.isnull(np.array([np.nan, 0], dtype=float))
df = df.replace(0,np.nan)
df = df.replace(1,np.inf)
plt.subplot2grid((3, 3), (2, 0), colspan=3)
plt.suptitle('Analysis of data in cycle Nr.{count}', fontsize=14, fontweight='bold')
plt.subplots_adjust(hspace=0.5, bottom=0.1)
sns.heatmap(df.isnull(),cbar=False)
plt.text(3, 4, r'nan={c} inf={d}',
verticalalignment='bottom', horizontalalignment='right', color='green', fontsize=15)
nan = np.array(df.isnull())
inf = np.array(df.isnull())
count_nan = len(df) - df.count()
print(count_nan)
c = 0
for i in nan:
for j in i:
if j:
c += 1
print(f'Total nan: {c}')
d = 1
for i in inf:
for j in i:
if j:
d += 1
print(f'Total inf: {d}')
plt.title(f'Total missing values: {c+d}', fontsize=12, color='black',
loc='left', style='italic')
plt.axis('off')
cycles = int(len(main_data)/480)
print(f'Total cycles: {cycles}')
for i in main_data:
for cycle in range(3):
count = '{:04}'.format(cycle)
j = cycle * 480
ordered_data = mkdf(main_data.iloc[j:j+480][i])
csv = print_df(ordered_data)
csv.to_csv(f'{i}{count}.csv', header=None, index=None)
Sections = mkdf(ordered_data)
df = print_df(Sections)
plt.title(i, fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.savefig(f'{i}{count}.png')
plt.clf()
'''
Speed plot
'''
Speed_df = pd.read_csv("Speed.csv",header=None)
plt.subplot2grid((3, 3), (0, 0), colspan=1)
sns.heatmap(Speed_df, vmin=-1, vmax=1, cmap ="coolwarm")
plt.title('Speed', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Speed missing plot
'''
Speed_df = pd.read_csv("Speed.csv",header=None)
Speed_df = Speed_df.replace(0,np.nan)
plt.subplot2grid((3, 3), (1, 0), colspan=1)
sns.heatmap(Speed_df.isnull(),cbar=False)
plt.title(f'Speed MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
acceleration plot
'''
acc_df = pd.read_csv("acceleration.csv",header=None)
plt.subplot2grid((3, 3), (0, 1), colspan=1)
sns.heatmap(acc_df, vmin=-1, vmax=1, cmap ="coolwarm")
plt.title('acceleration', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
acceleration missing plot
'''
acceleration_df = pd.read_csv("acceleration.csv",header=None)
acceleratione_df = acceleration_df.replace(0,np.nan)
plt.subplot2grid((3, 3), (1, 1), colspan=1)
sns.heatmap(acceleration_df.isnull(),cbar=False)
plt.title(f'accel MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Temperature plot
'''
temp_df = pd.read_csv("temperature.csv",header=None)
plt.subplot2grid((3, 3), (0, 2), colspan=1)
sns.heatmap(temp_df, vmin=-40, vmax=150, cmap ="coolwarm")
plt.title('Temperature', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Temperature missing plot
'''
temperature_df = pd.read_csv("temperature.csv",header=None)
temperature_df = temperature_df.replace(0,np.nan)
temperature_df = temperature_df.replace(0,np.inf)
plt.subplot2grid((3, 3), (1, 2), colspan=1)
sns.heatmap(temperature_df.isnull(),cbar=False)
plt.title(f'temp MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.show()
My desired result is:

I also provide sample text file of dataset for 3 cycles:
dataset
python dataframe typeerror seaborn missing-data
I wrote codes to demonstrate values of 3 parameters[Speed, Acceleration, Temperature] from my dataset(text file) via HeatMap plots in 24x20 matrices form. Data in text file were saved in this order:
Pointer-Speed-Acceleration-Temperature
and repeated many times and after 480times repeated again as 2nd cycle and so on.
So I extracted these main parameters and put them in lists and for each parameter in each cycle I print and save csv file and try to plot each values and also try to plot missing values(includes nan and inf) for every parameter and try to get all plots in one window with title of right cycle number and try to count missing values(not only nan but also inf) to mention next plots during getting plot for them via insnull and replacing missing values by 0 ( I prefer Nan and Inf replaced by last available value in previous cycle or in the best case replace by mean of values of last and next available cycles instead of 0 )but I've faced below error:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
I'm wondering if there's a elegant way to count inf and nan separately in lists and print them out in plot window via HeatMap and isnull for each cycle including counting info and save them somewhere in hard disk for other tasks.
My scripts are following:
import sys
import os
import numpy as np
import pandas as pd
#from sklearn.preprocessing import minmax_scale
import seaborn as sns
import matplotlib.pyplot as plt
def mkdf(ListOf480Numbers):
normalMatrix = np.array_split(ListOf480Numbers,8)
fixMatrix =
for i in range(8):
lines = np.array_split(normalMatrix[i],6)
newMatrix = [0,0,0,0,0,0]
for j in (1,3,5):
newMatrix[j] = lines[j]
for j in (0,2,4):
newMatrix[j] = lines[j][::-1]
fixMatrix.append(newMatrix)
return fixMatrix
def print_df(fixMatrix):
values =
for i in range(6):
values.append([*fixMatrix[6][i], *fixMatrix[7][i]])
for i in range(6):
values.append([*fixMatrix[4][i], *fixMatrix[5][i]])
for i in range(6):
values.append([*fixMatrix[2][i], *fixMatrix[3][i]])
for i in range(6):
values.append([*fixMatrix[0][i], *fixMatrix[1][i]])
df = pd.DataFrame(values)
return (df)
df = pd.read_csv('D:me4.TXT', header=None)
id_set = df[df.index % 4 == 0].astype('int').values
Speed = df[df.index % 4 == 1].values
Acceleration = df[df.index % 4 == 2].values
Temperature = df[df.index % 4 == 3].values
data = {'Speed': Speed[:,0], 'Acceleration': Acceleration[:,0], 'Temperature': Temperature[:,0]}
main_data = pd.DataFrame(data, columns=['Speed','Acceleration','Temperature'], index = id_set[:,0])
def plotheatmap(new_value):
Sections = mkdf(new_value)
df = print_df(Sections)
sns.heatmap(df, vmin=min_nor, vmax=max_nor, cmap ='coolwarm')
plt.title(i, fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.savefig(f'{i}/{i}{count}.png')
plt.clf()
return
'''
Missing data plot
'''
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]})
#pd.isnull(np.array([np.nan, 0], dtype=object))
pd.isnull(np.array([np.nan, 0], dtype=float))
df = df.replace(0,np.nan)
df = df.replace(1,np.inf)
plt.subplot2grid((3, 3), (2, 0), colspan=3)
plt.suptitle('Analysis of data in cycle Nr.{count}', fontsize=14, fontweight='bold')
plt.subplots_adjust(hspace=0.5, bottom=0.1)
sns.heatmap(df.isnull(),cbar=False)
plt.text(3, 4, r'nan={c} inf={d}',
verticalalignment='bottom', horizontalalignment='right', color='green', fontsize=15)
nan = np.array(df.isnull())
inf = np.array(df.isnull())
count_nan = len(df) - df.count()
print(count_nan)
c = 0
for i in nan:
for j in i:
if j:
c += 1
print(f'Total nan: {c}')
d = 1
for i in inf:
for j in i:
if j:
d += 1
print(f'Total inf: {d}')
plt.title(f'Total missing values: {c+d}', fontsize=12, color='black',
loc='left', style='italic')
plt.axis('off')
cycles = int(len(main_data)/480)
print(f'Total cycles: {cycles}')
for i in main_data:
for cycle in range(3):
count = '{:04}'.format(cycle)
j = cycle * 480
ordered_data = mkdf(main_data.iloc[j:j+480][i])
csv = print_df(ordered_data)
csv.to_csv(f'{i}{count}.csv', header=None, index=None)
Sections = mkdf(ordered_data)
df = print_df(Sections)
plt.title(i, fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.savefig(f'{i}{count}.png')
plt.clf()
'''
Speed plot
'''
Speed_df = pd.read_csv("Speed.csv",header=None)
plt.subplot2grid((3, 3), (0, 0), colspan=1)
sns.heatmap(Speed_df, vmin=-1, vmax=1, cmap ="coolwarm")
plt.title('Speed', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Speed missing plot
'''
Speed_df = pd.read_csv("Speed.csv",header=None)
Speed_df = Speed_df.replace(0,np.nan)
plt.subplot2grid((3, 3), (1, 0), colspan=1)
sns.heatmap(Speed_df.isnull(),cbar=False)
plt.title(f'Speed MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
acceleration plot
'''
acc_df = pd.read_csv("acceleration.csv",header=None)
plt.subplot2grid((3, 3), (0, 1), colspan=1)
sns.heatmap(acc_df, vmin=-1, vmax=1, cmap ="coolwarm")
plt.title('acceleration', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
acceleration missing plot
'''
acceleration_df = pd.read_csv("acceleration.csv",header=None)
acceleratione_df = acceleration_df.replace(0,np.nan)
plt.subplot2grid((3, 3), (1, 1), colspan=1)
sns.heatmap(acceleration_df.isnull(),cbar=False)
plt.title(f'accel MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Temperature plot
'''
temp_df = pd.read_csv("temperature.csv",header=None)
plt.subplot2grid((3, 3), (0, 2), colspan=1)
sns.heatmap(temp_df, vmin=-40, vmax=150, cmap ="coolwarm")
plt.title('Temperature', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
'''
Temperature missing plot
'''
temperature_df = pd.read_csv("temperature.csv",header=None)
temperature_df = temperature_df.replace(0,np.nan)
temperature_df = temperature_df.replace(0,np.inf)
plt.subplot2grid((3, 3), (1, 2), colspan=1)
sns.heatmap(temperature_df.isnull(),cbar=False)
plt.title(f'temp MV: {c}', fontsize=12, color='black', loc='left', style='italic')
plt.axis('off')
plt.show()
My desired result is:

I also provide sample text file of dataset for 3 cycles:
dataset
python dataframe typeerror seaborn missing-data
python dataframe typeerror seaborn missing-data
edited Dec 30 '18 at 8:30
Mario
asked Dec 30 '18 at 2:50
Mario Mario
146
146
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53974940%2ftypeerror-during-getting-heatmap-plot-for-missing-data-includes-inf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53974940%2ftypeerror-during-getting-heatmap-plot-for-missing-data-includes-inf%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown