I have a Pandas dataframe
of the following format, which consists of a ColumnA
with entries, and an IsMatching
Column with True/False values.
ColumnA IsMatching
0. asdasdas True
1. bsdasdas False
2. csdasdas False
3. dsdasdas True
4. 4455sdas False
5. asdasdas False
6. ppdasdas False
7. jjdasdas True
...
The aim is to create a new dataframe
column (NewColumn)
, which contains ColumnA
elements in between the 2 True
instances as a list
(wherever a True
occurs in IsMatching
Column, the list
needs to be placed there, otherwise, the NewColumn
values should be kept empty).
ColumnA NewColumn IsMatching
0. asdasdas [bsdasdas,csdasdas] # As 2 Falses True
between dataframe indices 0 and 3.
1. bsdasdas Keep This Empty False
2. csdasdas Keep This Empty False
3. dsdasdas [4455sdas,asdasdas,ppdasdas] # As 3 Falses
between dataframe indices 3 and 7.
4. esdasdas ....
Any suggestions and help in achieving this would be much appreciated.