I have the table below and would like to apply onde command to compare and eliminate duplicate values ββin row n and n + 1 in multiple dataframes (df1, df2).
Comand sugestion: .diff().ne(0)
How to apply this command only to the elements of columns A ,C and D, using the commands def ,lambda or apply?
df1:
| A | B |
|---|---|
| 22 | 33 |
| 22 | 4 |
| 3 | 55 |
| 1 | 55 |
df2:
| C | D |
|---|---|
| 5 | 2.3 |
| 45 | 33 |
| 7 | 33 |
| 7 | 11 |
The expected output is:
df1:
| A | B |
|---|---|
| 22 | 33 |
| NaN | 4 |
| 3 | 55 |
| 1 | 55 |
df2:
| C | D |
|---|---|
| 5 | 2.3 |
| 45 | 33 |
| 7 | NaN |
| NaN | 11 |
The other desired option would be to delete the duplicated lines, keeping the first number.
df1:
| A | B |
|---|---|
| 22 | 33 |
| row deleted | row deleted |
| 3 | 55 |
| row deleted | row deleted |
df2:
| C | D |
|---|---|
| 5 | 2.3 |
| 45 | 33 |
| row deleted | row deleted |
| row deleted | row deleted |