I have a pandas dataframe that looks like this:
| index | array | array2 |
|---|---|---|
| 1 | ['group1'] |
['group1, 'group3'] |
| 2 | ['group1', 'group4] |
['group1', 'group3'] |
| 3 | [] |
['group2', 'group3'] |
| 4 | [] |
['group2', 'group4'] |
as you can see, some of these arrays are zero-dimensional (to be specific: they are
array([], dtype=object
)
Now, because zero-dimensional arrays can not be concatenated, I want to replace them as np.nans so that I can concatenate them.
but if I do
data['array'].replace(np.array([]).astype(object), 0, inplace= True)
Nothing happens! The dataframe stays the same and nothing changes. In fact, even if I do it manually:
data['array'].replace(data['array'][3], 0, inplace = True)
my resulting dataframe is not altered at all...
My question then is, how can we create a function to replace all of these zero-dimensional arrays in a data frame for concatenation?