Python Forum
Pandac_concat - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Pandac_concat (/thread-2720.html)



Pandac_concat - yamanda - Apr-05-2017

Dear all

I want to combine two different data frames in one so i have a code
Quote:SUM=pd.concat([SUM_1a, result_F1], join='outer' ,axis=1, ignore_index=True


and it shows me these:

0   156790.0  YES  12345.0  Field 1          NaN  NaN  NaN  NaN  NaN  NaN   
1   156790.0  YES  12345.0  Field 1          NaN  NaN  NaN  NaN  NaN  NaN   
2   156790.0  YES  12345.0  Field 1          NaN  NaN  NaN  NaN  NaN  NaN   
3   156790.0  YES  12345.0  Field 1          NaN  NaN  NaN  NaN  NaN  NaN   
4   156790.0  YES  12345.0  Field 1          NaN  NaN  NaN  NaN  NaN  NaN   
16       NaN  NaN      NaN      NaN  Ver_point_1    0    0    0    2  NaN   
17       NaN  NaN      NaN      NaN  Ver_point_2    0    0    0    3  NaN   
18       NaN  NaN      NaN      NaN  Ver_point_3    0    0    0    4  NaN   
19       NaN  NaN      NaN      NaN  Ver_point_4    0    0    0    5  NaN   
20       NaN  NaN      NaN      NaN  Ver_point_5    0    0    0    6  NaN   

     10       11   12   13     14  
0   NaN      NaN  NaN  NaN    NaN  
1   NaN      NaN  NaN  NaN    NaN  
2   NaN      NaN  NaN  NaN    NaN  
3   NaN      NaN  NaN  NaN    NaN  
4   NaN      NaN  NaN  NaN    NaN  
16  NaN  Plane_1    0    0  Note:  
17  NaN  Plane_2    0    0  Note:  
18  NaN  Plane_3    0    0  Note:  
19  NaN  Plane_4    0    0  Note:  
20  NaN  Plane_5    0    0  Note:  

How to combine without 16-20 rows??
Thank you :)


RE: Pandac_concat - zivoni - Apr-05-2017

You are still joining on index values, parameter ignore_axis=True means ignoring index values on concatenating axis (in this case it removes columns names). To "ignore index" on rows axis you need to set both indices to same values - you can reset them but its faster to set second index as first one ...

Simple example:
Output:
In [3]: df1 = pd.DataFrame({'A':[1,2], 'B':['yes', 'no']}) In [4]: df2 = pd.DataFrame({'C':['foo','boo']}, index=[2,3]) In [5]: pd.concat([df1, df2], axis=1) Out[5]:      A    B    C 0  1.0  yes  NaN 1  2.0   no  NaN 2  NaN  NaN  foo 3  NaN  NaN  boo In [6]: df2.index = df1.index In [7]: pd.concat([df1, df2], axis=1) Out[7]:    A    B    C 0  1  yes  foo 1  2   no  boo



RE: Pandac_concat - yamanda - Apr-05-2017

Yes it works. Thank You very much :)