I have a Pandas series of lists:
| id | values |
| -- | -------------- |
| 0 | ['a', 'b'] |
| 1 | ['c'] |
| 2 | ['b', 'c'] |
I want to apply a function to each of the lists.
Let's use a really simple function that just adds 'd' to each list, and apply it to the series:
def append_d(x):
print(x)
return x + ['d']
my_series.apply(append_d)
This results in an error:
Cannot broadcast np.ndarray with operand of type <class 'list'>
I have tried the following:
my_series.apply(lambda x: x + ['d']) # same error as above
my_series.transform(append_d) # ValueError: Transform function failed
my_series.transform(lambda x: x + ['d']) # ValueError: Transform function failed
How do I use apply/transform with a series of lists?