我认为您要寻找的是:
假设您的框架是:
frame = pd.Dataframe(np.random.rand(10, 6), columns=['cost', 'amount', 'day', 'month', 'is_sale', 'hour'])
您希望
'cost'和
'amount'列与每种组合中的所有其他列相关联。
focus_cols = ['cost', 'amount']frame.corr().filter(focus_cols).drop(focus_cols)
回答您的问题:
计算两个Dataframe对象的行或列之间的成对关联。
参数:
其他 :Dataframe
轴:{0或“索引”,1或“列”},
默认值0
0或’index’用于计算按列,1或’columns’用于按行删除:布尔值,默认False从结果中删除缺少的索引,默认返回所有并集的返回:correls:Series
corrwith同样表现于
add,
sub,
mul,
div,它希望找到一个
Dataframe或
Series在被传递
other,尽管文档只是说
Dataframe。
当
other是
Series它的广播沿着指定的轴那个系列和火柴
axis,默认值为0。这就是为什么以下工作:
frame.drop(labels='a', axis=1).corrwith(frame.a)b -1.0c 0.0dtype: float64
当
other为时
Dataframe,它将与指定的轴匹配
axis并关联由另一轴标识的每一对。如果我们这样做:
frame.drop('a', axis=1).corrwith(frame.drop('b', axis=1))a NaNb NaNc 1.0dtype: float64仅
c存在共同点,并且仅
c计算了其相关性。
在您指定的情况下:
frame.drop(labels='a', axis=1).corrwith(frame[['a']])
frame[['a']]是
Dataframe由于的原因,
[['a']]现在按
Dataframe规则运行,其中的列必须与其关联的内容匹配。但是你明确地下降
a,从第一帧,然后用相关
Dataframe一无所有
a。结果适用
NaN于每一列。



