I have a dataframe like z:
z <- matrix(c(1,0,0,1,1,0,0,
1,0,0,0,1,0,0,
0,0,0,0,0,0,0,
0,0,1,0,0,0,0),
nrow=7,
dimnames=list(LETTERS[1:7],NULL))
[,1] [,2] [,3] [,4]
A 1 1 0 0
B 0 0 0 0
C 0 0 0 1
D 1 0 0 0
E 1 1 0 0
F 0 0 0 0
G 0 0 0 0
Now I want to remove the duplicated rows where the values of column 1, 2, and 3 are the same.
The result should be like this:
[,1] [,2] [,3] [,4]
A 1 1 0 0
B 0 0 0 0
D 1 0 0 0
Could anyone help me with this? Many thanks!
Use drop() method to delete rows based on column value in pandas DataFrame, as part of the data cleansing, you would be required to drop rows from the DataFrame when a column value matches with a static value or on another column value.
The Pandas dataframe drop() method takes single or list label names and delete corresponding rows and columns. The axis = 0 is for rows and axis =1 is for columns. In this example, we are deleting the row that 'mark' column has value =100 so three rows are satisfying the condition.
> z[rownames(unique(z[,-4])),]
[,1] [,2] [,3] [,4]
A 1 1 0 0
B 0 0 0 0
D 1 0 0 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With