【发布时间】:2021-09-29 05:43:26
【问题描述】:
假设我是
common_indices = df1.index.intersection(df2.index)
产生一个<class 'pandas.core.indexes.base.Index'> 对象,我如何检索与另一个数据帧关联的值(例如df3)。
尝试
sub_df3 = df3.where(df3.index == common_indices)
产生ValueError: Lengths must match to compare
【问题讨论】:
-
你想用
df3做什么?当您执行df3.index == common_indices时,它试图做的是根据元素相等创建一个真假数组。