Search code examples
pythonpandaspandas-explode

Applying explode on a pandas dataframe results in the error 'ValueError: column must be a scalar'


Here the dataframe before attempting to explode it:

                   Acc # Match Length        Gene      Identity (%)
0             CP034360.1        [312]     [b4172]          [88.462]
1             CP098173.1  [1655, 180]  [rne, rne]  [84.955, 85.556]
2         NTCW01000078.1        [986]      [recA]          [90.974]
3   NZ_JASISD010000003.1        [312]     [b4172]          [88.462]
4         PEGY01000004.1  [1619, 183]  [rne, rne]  [85.238, 85.246]
5         PEHS01000009.1        [312]     [b4172]          [87.500]
6         PEHS01000011.1       [1608]       [rne]          [85.759]
7         PEHV01000004.1       [1014]      [recA]          [90.335]
8         PEHV01000005.1       [2417]      [gyrB]          [88.746]
9         PEHV01000008.1        [312]     [b4172]          [87.500]
10        VOOC01000097.1       [2423]      [gyrB]          [88.816]

The command that causes the error is

b_df.explode(['Match Length', 'Gene', 'Identity (%)'])

I couldn't find what might cause this error, or relevant posts.
Any ideas will be welcomed.
Thanks.


Solution

  • Multi-column explode is only available in pandas >= 1.3.0, see here