Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas explode error - column must be scalar

df.explode(['X'])


ValueError: column must be a scalar

Hi anyone could advice on this?

like image 706
Tonz Avatar asked Oct 18 '25 09:10

Tonz


2 Answers

You can supply a list or tuple of column names, but only with pandas >= 1.3.0: see https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.explode.html

New in version 1.3.0: Multi-column explode

If you see this ValueError you must be using an older version of pandas

like image 93
delocalizer Avatar answered Oct 21 '25 00:10

delocalizer


Use df.explode('X') instead of df.explode(['X']). Example on pandas explode page explains this.

like image 25
Tejash Shah Avatar answered Oct 21 '25 01:10

Tejash Shah