I am trying this simple setup of variables:
In [94]: cc
Out[94]:
d0 d1
class sample
5 66 0.128320 0.970817
66 0.160488 0.969077
77 0.919263 0.008597
6 77 0.811914 0.123960
88 0.639887 0.262943
88 0.312303 0.660786
In [101]: bb
Out[101]:
d0 d1
class sample
2 22 0.730631 0.656266
33 0.871292 0.942768
3 44 0.081831 0.714360
55 0.600095 0.770108
In [102]: aa
Out[102]:
d0 d1
class sample
0 00 0.190409 0.789750
11 0.588001 0.250663
1 22 0.888343 0.428968
33 0.185525 0.450020
I can perform the following command
In [103]: aa.append(bb)
Out[103]:
d0 d1
class sample
0 00 0.190409 0.789750
11 0.588001 0.250663
1 22 0.888343 0.428968
33 0.185525 0.450020
2 22 0.730631 0.656266
33 0.871292 0.942768
3 44 0.081831 0.714360
55 0.600095 0.770108
Why I cant perform the following command in the same manner?
aa.append(cc)
[I get the following exception]
ValueError: all arrays must be same length
UPDATE:
It works fine if I did not provide column names, but if for example I have 4 columns, with names [‘d0′,’d0′,’d1′,’d1’] for 4X4 and 8X4, it does not work anymore
here is the code for reproducing the error
import pandas
y1 = [['0','0','1','1'],['00','11','22','33']]
y2 = [['2','2','3','3','4','4'],['44','55','66','77','88','99']]
x1 = np.random.rand(4,4)
x2 = np.random.rand(6,4)
cols = ['d1']*2 + ['d2']*2
names = ['class','idx']
aa = pandas.DataFrame(x1,index=y1,columns = cols)
aa.index.names = names
print aa
bb = pandas.DataFrame(x2,index=y2,columns = cols)
bb.index.names = names
print bb
aa.append(bb)
What should I do to get this running?
Thanks
Answer To Your Edited Question
So to answer your edited question, the problem lies with your column names having duplicates.
and your dataframes end up having what-is-considered duplicated columns, i.e.
and
pandas.append()(orconcat()method) can only append correctly if you have unique column names.Try this and you will not get any error:-
Now…