votes up 3

cannot concatenate unaligned mixed dimensional NDFrame objects

Package:
pandas
github stars 30911
Exception Class:
ValueError

Raise code

in objs:

                ndim = obj.ndim
                if ndim == max_ndim:
                    pass

                elif ndim != max_ndim - 1:
                    raise ValueError(
                        "cannot concatenate unaligned mixed "
                        "dimensional NDFrame objects"
                    )

                else:
                    name = getattr(obj, "name", None)
                    if ignore_index or name is None:
                    
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 1 votes down

pd.concat concatenates pandas objects along a particular axis with optional set logic along the other axes.

It's possible to concatenate Series or DataFrame each other. Depend on their dimension, the operation can be done. But when trying to concatenate mixed dimensional NDFrame object, it becomes an error. Concatenate of the sequential dimensional object is allowed.

Like

import pandas as pd 

df1 = pd.DataFrame([['a'1], ['b'2]],
                   columns=['letter''number'])

df2 = pd.DataFrame([['c'3], ['d'4]],
                   columns=['letter''number'])

conci = pd.concat([df1,df2],axis=1)
print(conci)

But if you want to try to concatenate 1D and 3D DataFrame, that will cause an error.

elif ndim != max_ndim - 1:
    raise ValueError(
        "cannot concatenate unaligned mixed "
        "dimensional NDFrame objects"
    )

When max_ndim (maximum dimension in list of DataFrame or Series) is 3 and ndim (current object which is iterated) is 1, the result will be 1!=2 i.e return to True and will be thrown an error.

Jul 24, 2021 anonim answer
anonim 13.0k

Add a possible fix

Please authorize to post fix