Say I have two series: a and b,
a = Series(None, index=['a','b','c'])
b = Series('lol', index=['j','k','l'])
I would like to store b as one of the elements of a,
a['a'] = b
but I get
ValueError: setting an array element with a sequence.
Is it possible to store a pandas series inside a pandas series? How can I do it? Thanks.
You can recast the
dtypeusing the methodastype:Alternatively (to using
astype) when contructingayou can force thedtypeto be object:The reason you are getting this error is because
float64, doesn’t allow aSeriesand similarly it doesn’t allow strings – try to seta['a'] = 'lol'and you’ll get aValueError.You can read more about type-casting in the docs.