I have a dataframe as shown below:
A B 0 3 4 5 8
timestamp
2022-05-09 09:28:00 0 45 NaN 20 30 NaN NaN
2022-05-09 09:28:01 3 100 NaN 20 NaN 30 20
2022-05-09 09:28:02 4 30 NaN NaN 10 NaN 40
2022-05-09 09:28:03 5 20 NaN NaN 20 90 NaN
2022-05-09 09:28:04 8 10 NaN NaN 10 30 NaN
The values present in A that is 0,3,4,5 and 8 are present as columns in the dataframe.
The idea is in each row, value present in column A
is noted and if the corresponding column has a value in it, it must be changed to NaN. For eg: In the second row of the dataframe, the value in column A
is 3, so for the same row, the column 3
is checked, if it has a value, in this case 20, it must be changed to NaN (as shown below)
A B 0 3 4 5 8
timestamp
2022-05-09 09:28:00 0 45 NaN 20 30 NaN NaN
2022-05-09 09:28:01 3 100 NaN NaN NaN 30 20
2022-05-09 09:28:02 4 30 NaN NaN NaN NaN 40
2022-05-09 09:28:03 5 20 NaN NaN 20 NaN NaN
2022-05-09 09:28:04 8 10 NaN NaN 10 30 NaN
Is there a function in Pandas to do this directly?
Thanks in advance!