简体   繁体   中英

pandas dataframe computation between columns

I have a panda dataframe. Given two columns, I'd like to compute the following

(sum(xy) - sum(x)*sum(y)/n)^2

Here x is an element in the first column, y is the corresponding element in the second column, and n is the length of the column.

I'd like to compute the above between df.column[0] and every other column. Then I would like to get the column index that corresponds to the smallest value.

这样的事情可能是?

((df['x'] * df['y']).sum() - df['x'].sum() * df['y'].mean()) ** 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM