Can I do the following conversion to an array, using constructs like df.col.apply(lambda x ...
, without using 'traditional' for-loops (one iterating over the columns and another iterating over words within each column's string value)?
All my attempts gave error messages like The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
.
Example:
d = {'foo' : [1,2,3], 'bar': [-2,-2,-3]}
df = pd.DataFrame({'col': ['foo mur bar','foo','mur mur']}, index=[1,2,3])
Expected output is:
np.array([
[[1,2,3],[-2,-2,-3]],
[[1,2,3]],
[[]]
])