If I have an array with column indices for each row like this:
array = [NaN, 3, 4, 3, NaN]
And a pandas data frame like this:
1 2 3 4 5 6
1 1 NaN NaN NaN NaN 1
2 1 1 1 NaN NaN 1
3 NaN 1 1 1 1 1
4 NaN 1 1 1 NaN 1
5 1 NaN 1 NaN NaN 1
How do I keep values that overlap with my column index for each row such that I get a data frame like this:
1 2 3 4 5 6
1 NaN NaN NaN NaN NaN NaN
2 1 1 1 NaN NaN NaN
3 NaN 1 1 1 1 1
4 NaN 1 1 1 NaN NaN
5 NaN NaN NaN NaN NaN NaN
Where data associated with my rows column index is preserved? Basically, I want to only keep data that intersects and is surrounded by my column index.
from How to only keep data surrounding a line/column intersection in Pandas Data frame?
No comments:
Post a Comment