我有一个数据集X,比如说2000行。我想把每两行的意思一列一列地放在一起。结果应该是一个1000行的数据集(列计数应该保持不变)。你知道吗
我已经用matlab做过了
#matlab function
function [ divisibleMatrix ] = meanDown( matrix )
%MEANDOWN takes a matrix and means every 2 lines (makes it half the size)
newSize = (floor(size(matrix, 1)/2)*2); %make it divisible
divisibleMatrix = matrix(1:newSize, 1:end);
D = divisibleMatrix;
m=size(divisibleMatrix, 1);
n=size(divisibleMatrix, 2);
% compute mean for two neighboring rows
D=reshape(D, 2, m/2*n);
D=(D(1,:)+D(2,:))/2;
D=reshape(D, m/2, n);
divisibleMatrix = D;
end
这是单行线。关键是groupby可以对index->;group进行任意映射。
df.index / 2
给出了你所看到的。你知道吗相关问题 更多 >
编程相关推荐