无法绘制一列相对于其他列的热图
Not able to plot the heatmap of one column with respect to others
在问题的帮助下:,我尝试了以下方法:
import pandas
import seaborn as sns
dataframe = pandas.read_csv("training.csv", header=0,index_col=0)
for a in list(['output']):
for b in list(dataframe.columns.values):
corr.loc[a, b] = dataframe.corr().loc[a, b]
print(b)
print(corr)
sns.heatmap(corr['output'])
我收到以下错误:
IndexError: Inconsistent shape between the condition and the input (got (8, 1) and (8,))
我不想让所有值与所有值相关的热图。我只想获得一列与其他列的相关性。
请告诉我我缺少什么。
行中
sns.heatmap(corr['output'])
corr['output']
是一个 pd.Series
。 documentation 状态
data
: rectangular dataset
2D dataset that can be coerced into an ndarray. If a Pandas DataFrame is provided, the index/column information will be used to label the columns and rows.
你写
I do not want to have the all values correlation heatmap with all values. I only want to have the correlation of one column with respect to others.
在这种情况下,为什么要使用热图?您的数据是一维的。您可能想要使用条形图,例如,使用 pd.DataFrame.corrwith
:
dataframe.corrwith(dataframe['some_specific_column']).plot(kind='barh')
您正在尝试从 pd.Series
构建热图 - 这不起作用。 pd.Series
是一维对象,而 seaborn.heatmap()
通常用于二维数据结构。
sns.heatmap(corr[['output']])
- 能胜任
df = pd.DataFrame(data=[[1,2,3],[5,4,3],[5,4,12]],index=[0,1,2],columns=['A','B','C'])
df.corr().loc['A',:]
输出[13]:
A 1.0
B 1.0
摄氏度 0.5
名称:A,数据类型:float64
sns.heatmap(df.corr().loc[['A'],:])
在问题的帮助下:
import pandas
import seaborn as sns
dataframe = pandas.read_csv("training.csv", header=0,index_col=0)
for a in list(['output']):
for b in list(dataframe.columns.values):
corr.loc[a, b] = dataframe.corr().loc[a, b]
print(b)
print(corr)
sns.heatmap(corr['output'])
我收到以下错误:
IndexError: Inconsistent shape between the condition and the input (got (8, 1) and (8,))
我不想让所有值与所有值相关的热图。我只想获得一列与其他列的相关性。
请告诉我我缺少什么。
行中
sns.heatmap(corr['output'])
corr['output']
是一个 pd.Series
。 documentation 状态
data
: rectangular dataset2D dataset that can be coerced into an ndarray. If a Pandas DataFrame is provided, the index/column information will be used to label the columns and rows.
你写
I do not want to have the all values correlation heatmap with all values. I only want to have the correlation of one column with respect to others.
在这种情况下,为什么要使用热图?您的数据是一维的。您可能想要使用条形图,例如,使用 pd.DataFrame.corrwith
:
dataframe.corrwith(dataframe['some_specific_column']).plot(kind='barh')
您正在尝试从 pd.Series
构建热图 - 这不起作用。 pd.Series
是一维对象,而 seaborn.heatmap()
通常用于二维数据结构。
sns.heatmap(corr[['output']])
- 能胜任
df = pd.DataFrame(data=[[1,2,3],[5,4,3],[5,4,12]],index=[0,1,2],columns=['A','B','C'])
df.corr().loc['A',:]
输出[13]:
A 1.0
B 1.0
摄氏度 0.5
名称:A,数据类型:float64
sns.heatmap(df.corr().loc[['A'],:])