MKoosej MKoosej - 8 months ago 73
Python Question

how to combine two data frames in python pandas

I'm using python pandas data frame , I have a initial data frame say D. I extract two data frames from it like this:

A = D[D.label == k]

B = D[D.label != k]

then I change the label in A and B:

A.label = 1

B.label = -1

I want to combine A and B so I can have them as one data frame something like union. The order of the data not important , however when we sample A and B from D they retain their indexes from D.


I believe you can use the append method

bigdata = data1.append(data2, ignore_index=True)

to keep their indexes just dont use the ignore_index keyword ...