nikosd
nikosd

Reputation: 949

How can I avoid repeated indices in pandas DataFrame after concat?

I have two pandas dataframes and concatenate them:

In[55]: adict  = {'a':[0, 1]}
        bdict = {'a': [2, 3]}
        dfa = DataFrame(adict)
        dfb = DataFrame(bdict)
        dfab = pd.concat([dfa,dfb])

The problem is, the resulting dataframe has repeated index.

In [56]: dfab.head()

Out[56]:
                a
          0     0
          1     1
          0     2
          1     3

How can I have a single index running through the resulting dataframe, i.e.

In [56]: dfab.head()

Out[56]:
                a
          0     0
          1     1
          2     2
          3     3

Upvotes: 4

Views: 1147

Answers (1)

CT Zhu
CT Zhu

Reputation: 54330

Just do: dfab = pd.concat([dfa,dfb], ignore_index=True)

Upvotes: 5

Related Questions