If you want to combine a subset of your df columns, use pd.concat :
pd.concat([comb.ix[:,0:1],comb.ix[:,17:342]], axis=1)
As long as the indices match, it will align correctly.
Thanks to @iHightower, you can also choose by passing shortcuts:
pd.concat([df.ix[:,'Col1':'Col5'],df.ix[:,'Col9':'Col15']],aββxis=1)
Please note that .ix become obsolete in the next version, the following should work:
In [115]: df = pd.DataFrame(columns=['col' + str(x) for x in range(10)]) df Out[115]: Empty DataFrame Columns: [col0, col1, col2, col3, col4, col5, col6, col7, col8, col9] Index: [] In [118]: pd.concat([df.loc[:, 'col2':'col4'], df.loc[:, 'col7':'col8']], axis=1)β Out[118]: Empty DataFrame Columns: [col2, col3, col4, col7, col8] Index: []
Or using iloc :
In [127]: pd.concat([df.iloc[:, df.columns.get_loc('col2'):df.columns.get_loc('col4')], df.iloc[:, df.columns.get_loc('col7'):df.columns.get_loc('col8')]], axis=1) Out[127]: Empty DataFrame Columns: [col2, col3, col7] Index: []
Please note that the iloc slicing iloc open / closed, so the final range is not included, so you will need to find the column after the column of interest if you want to include it:
In [128]: pd.concat([df.iloc[:, df.columns.get_loc('col2'):df.columns.get_loc('col4')+1], df.iloc[:, df.columns.get_loc('col7'):df.columns.get_loc('col8')+1]], axis=1) Out[128]: Empty DataFrame Columns: [col2, col3, col4, col7, col8] Index: []