Skip to content

concat() ignores ignore_index=True #2003

Closed
@etyurin

Description

@etyurin

Unless I misunderstood what the documentation says, this is not the intended behavior:

df1 = pandas.DataFrame({'a':np.arange(5),'b':np.arange(5)},index=3+np.arange(5))
df2 = pandas.DataFrame({'c':np.arange(5),'d':np.arange(5)})
pandas.concat([df1,df2],axis=1,ignore_index=False)
a b c d
0 NaN NaN 0 0
1 NaN NaN 1 1
2 NaN NaN 2 2
3 0 0 3 3
4 1 1 4 4
5 2 2 NaN NaN
6 3 3 NaN NaN
7 4 4 NaN NaN

The following function does a work-around for this bug by explicitly re-setting the index:

def myConcat(df1,df2):
if df1.shape[0] != df2.shape[0]:
return False
else:
df2.index = df1.index
return pandas.concat((df1,df2),axis=1)

Pandas version: commit de6cce5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions