MATLAB中的代码A(A(:,4)==0,:)=[];如果第四列中的值为零,则删除矩阵A中的行。我试着写一段A=A[A[:,4] !==0]的代码,因为pandas被调用了,但是在python中被拒绝了。如果代码在python中运行良好,我希望它会忽略第四列中的值为零的行。在excel中原始数据不会受到影响。
A(A(:,4)==0,:)=[];
A=A[A[:,4] !==0]
t1qtbnec1#
使用iloc选择列和布尔索引:
iloc
A = A[A.iloc[:, 4] != 0]
字符串变体:
A = A[A.iloc[:, 4].ne(0)] A = A.loc[A.iloc[:, 4] != 0] # only if the column name is unique A = A[A[A.columns[4]] != 0]
型
1条答案
按热度按时间t1qtbnec1#
使用
iloc
选择列和布尔索引:字符串
变体:
型