Remove rows from Dataframe where row above or below has same value in a specific column

FakeFootball

Starting Dataframe:

     A    B
0    1    1
1    1    2
2    2    3
3    3    4
4    3    5
5    1    6
6    1    7
7    1    8
8    2    9

Desired result - eg. Remove rows where column A has values that match the row above or below:

     A    B
0    1    1
2    2    3
3    3    4
5    1    6
8    2    9
Vaishali

You can use boolean indexing, the following condition will return true if value of A is NOT equal to value of A's next row

new_df = df[df['A'].ne(df['A'].shift())]

    A   B
0   1   1
2   2   3
3   3   4
5   1   6
8   2   9

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Selecting rows where column in child row has particular value?

분류에서Dev

LINQ to remove duplicate rows from a datatable based on the value of a specific row

분류에서Dev

Summing the above 7 rows in same column based on a value

분류에서Dev

Remove blank space above and below Google Charts horizontal column chart

분류에서Dev

Selecting rows with specific value in column

분류에서Dev

SQL - Return value from row above

분류에서Dev

How to get column name from table from 2 rows of same table having same value?

분류에서Dev

R: Extract rows from a dataframe where values from one column occur in a separate vector

분류에서Dev

pandas dataframe groupby a col if value present in the group by row assign the same to groups row or assign a max value from external and increment

분류에서Dev

Select rows from database where the value in one column is distinct and limit to 5 latest

분류에서Dev

column width not controlled by row above it

분류에서Dev

Select distinct rows where all values in a column are the same SQL Server

분류에서Dev

How to subset Julia DataFrame by condition, where column has missing values

분류에서Dev

MySQL return a single row only when all rows are the value of the WHERE

분류에서Dev

Calculation new column in pandas dataframe from row by row calculation

분류에서Dev

Splitting one Pandas column on values from a different column in the same row?

분류에서Dev

Filter a chunk of rows based on a specific value in another column in R

분류에서Dev

SQL Returning rows with max value in column, within a specific range

분류에서Dev

XOR of the value of the same column across different rows in MySQL

분류에서Dev

Pandas exclude row from dataframe if the value is absent in the other dataframe

분류에서Dev

Delete all rows where value in a column does not match value in column in another dataset

분류에서Dev

Grabbing all rows from a database that have specific column values in laravel

분류에서Dev

Remove words (letters followed by space) from a specific column

분류에서Dev

Search for column values in another column and assign a value from the next column from the row found to another column

분류에서Dev

how to remove specific rows in a matrix

분류에서Dev

mysql how to update a column of all rows and for each row a different column value

분류에서Dev

Copy data to new workbook and add specific text to each row´s value in a specific column

분류에서Dev

Recursively remove elements from nested array looking for a specific value

분류에서Dev

How to create new column that is named based on the value of another column in the same row?

Related 관련 기사

  1. 1

    Selecting rows where column in child row has particular value?

  2. 2

    LINQ to remove duplicate rows from a datatable based on the value of a specific row

  3. 3

    Summing the above 7 rows in same column based on a value

  4. 4

    Remove blank space above and below Google Charts horizontal column chart

  5. 5

    Selecting rows with specific value in column

  6. 6

    SQL - Return value from row above

  7. 7

    How to get column name from table from 2 rows of same table having same value?

  8. 8

    R: Extract rows from a dataframe where values from one column occur in a separate vector

  9. 9

    pandas dataframe groupby a col if value present in the group by row assign the same to groups row or assign a max value from external and increment

  10. 10

    Select rows from database where the value in one column is distinct and limit to 5 latest

  11. 11

    column width not controlled by row above it

  12. 12

    Select distinct rows where all values in a column are the same SQL Server

  13. 13

    How to subset Julia DataFrame by condition, where column has missing values

  14. 14

    MySQL return a single row only when all rows are the value of the WHERE

  15. 15

    Calculation new column in pandas dataframe from row by row calculation

  16. 16

    Splitting one Pandas column on values from a different column in the same row?

  17. 17

    Filter a chunk of rows based on a specific value in another column in R

  18. 18

    SQL Returning rows with max value in column, within a specific range

  19. 19

    XOR of the value of the same column across different rows in MySQL

  20. 20

    Pandas exclude row from dataframe if the value is absent in the other dataframe

  21. 21

    Delete all rows where value in a column does not match value in column in another dataset

  22. 22

    Grabbing all rows from a database that have specific column values in laravel

  23. 23

    Remove words (letters followed by space) from a specific column

  24. 24

    Search for column values in another column and assign a value from the next column from the row found to another column

  25. 25

    how to remove specific rows in a matrix

  26. 26

    mysql how to update a column of all rows and for each row a different column value

  27. 27

    Copy data to new workbook and add specific text to each row´s value in a specific column

  28. 28

    Recursively remove elements from nested array looking for a specific value

  29. 29

    How to create new column that is named based on the value of another column in the same row?

뜨겁다태그

보관