s = df[df['RootProduct'].eq(df['Product'])].set_index('Product')['Value']
df['RootValue'] = df['RootProduct'].map(s)
print (df)
RootProduct Product Value RootValue
0 A A 1 1
1 A B 2 1
2 A C 3 1
3 D D 4 4
4 D E 5 4
有关Series的详细信息:
print (s)
Product
A 1
D 4
Name: Value, dtype: int64
想法是通过^{} 和^{} 比较两列,然后通过} 索引创建} :
Product
和^{Series
,因此可以通过RootProduct
列使用^{有关
Series
的详细信息:相关问题 更多 >
编程相关推荐