How to a convert a pandas column of numpy arrays to lists?
Pandas dataframe construction
A = np.random.randint(0,15000000,65000)
B = [np.random.randint(0,15000000,k) for k in np.random.randint(2,101,100)]
A32 = A.astype(np.int32)
from itertools import chain
sizes = np.fromiter(chain((0,),map(len,B)),np.int32,len(B)+1)
boundaries = sizes.cumsum()
# force int32
B_all = np.empty(boundaries[-1],np.int32)
B32 = np.split(B_all, boundaries[1:-1])
df = pd.DataFrame([A32, B32]).T
Attempt to convert 2nd column to list
df[1] = df[1].apply(lambda x: x.tolist() )
Resulting error message
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-35-6d36b7b9c250> in <module>()
----> 1 df[1] = df[1].apply(lambda x: x.tolist() )
1 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
3589 else:
3590 values = self.astype(object).values
-> 3591 mapped = lib.map_infer(values, f, convert=convert_dtype)
3592
3593 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/lib.pyx in pandas._libs.lib.map_infer()
<ipython-input-35-6d36b7b9c250> in <lambda>(x)
----> 1 df[1] = df[1].apply(lambda x: x.tolist() )
AttributeError: 'float' object has no attribute 'tolist'