MKoosej MKoosej - 1 year ago 129
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.

Answer Source

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 ...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download