Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pandas

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
like image 268
nikosd Avatar asked Oct 15 '25 13:10

nikosd


1 Answers

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

like image 97
CT Zhu Avatar answered Oct 19 '25 15:10

CT Zhu