简体   繁体   English

将每一行与数据框中的其他行进行比较

[英]Compare each row to the other rows in a Dataframe

I have a dataframe containing a column of values (X). 我有一个包含一列值(X)的数据框。

df = pd.DataFrame({'X' : [2,3,5,2]})

For each row, I would like to find the average of the X values from the other rows (A). 对于每一行,我想查找其他行(A)中X值的平均值。

在此处输入图片说明

其他行的平均值是列的总和减去行值除以列的大小减去1。在Pandas中,其写为​​:

df['A'] = (df['X'].sum() - df['X'])/(len(df) - 1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据帧的一行与其他数据帧的行进行比较? - Compare one row of a dataframe with rows of other dataframe? 如何将一个数据框的每一行与另一数据框的所有行进行比较,并计算距离度量? - How to compare each row from one dataframe against all the rows from other dataframe and calculate distance measure? 仅比较数据框中的两行 - Compare only two rows in dataframe with each other 将数据帧第一行的单元格值与其他行的单元格值进行比较 - Compare cell value of first row of a dataframe to cell value of other rows 按给定类别将行值与其他行的总和进行比较 - Pandas dataframe - Compare row value with sum of other rows by given categories - Pandas dataframe Pandas Dataframe - 对于每一行,返回具有重叠日期的其他行的计数 - Pandas Dataframe - for each row, return count of other rows with overlapping dates Pandas 数据框获取每组的第一行并复制到其他行 - Pandas dataframe get first row of each group and copy to other rows 对于 Dataframe 中的每一行,测试所有其他行的条件 - For each row in Dataframe test all other rows for a condition 如何将数据帧的每一行与以下两行进行比较,并基于这三行和一种算法来修改当前行? (熊猫) - How to compare each row of a dataframe to the following 2 rows, and modify the current row based on these 3 rows and an algorithm? (Pandas) 如何迭代一个 dataframe 的每一行并与 Python 中的另一个 dataframe 中的行进行比较? - how to iterate each row of one dataframe and compare with rows in another dataframe in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM