0

I have the following dataframe,

    AA46                                AE48                    \
               Open     High      Low    Close     Open     High      Low   
2018-08-31  72.5700  72.5700  72.5700  72.5700  67.9300  67.9300  67.9300   
2018-08-30  74.7800  74.7800  74.7800  74.7800  70.6700  69.8000  70.6700   
2018-08-29  76.8600  76.8600  76.8600  76.8600  72.4900  72.4900  72.4900   
2018-08-28  77.5700  77.5700  77.5700  77.5700  71.7400  71.7400  71.7400   
2018-08-27  77.0000  77.0000  77.0000  77.0000  72.2400  72.2400  72.2400   

                          Date AA46_accrued_interest  AA46_ytm   AA46_md  \
              Close                                                        
2018-08-31  67.9300 2018-08-31              2.732292  0.110273  8.768597   
2018-08-30  69.8000 2018-08-30              2.711111  0.106907  8.981324   
2018-08-29  72.4900 2018-08-29              2.689931  0.103867  9.181275   
2018-08-28  71.7400 2018-08-28              2.668750  0.102863  9.248629   
2018-08-27  72.2400 2018-08-27              2.647569  0.103666  9.195037   

           AE48_accrued_interest  AE48_ytm    AE48_md beta0 beta1  

2018-08-31              0.954861  0.106488   9.206760     0     0  
2018-08-30              0.935764  0.103583   9.411606     0     0  
2018-08-29              0.916667  0.075194  15.210533     0     0  
2018-08-28              0.897569  0.100684   9.624328     0     0  
2018-08-27              0.878472  0.075965  15.036988     0     0  

Where there are columns with two index names and other that have names with "_" in the middle. I would like the later ones to have the same format of the first ones.

For example I would like the column AA46_accrued_interest a first index level AA46 and a second one being accrued_interest.

Thank you.

ruben
  • 127
  • 1
  • 9
  • Use `df.columns = df.columns.map('_'.join)` – jezrael Sep 10 '18 at 11:35
  • I'm trying to do exact opposite moving from columns with "_ " to a two level column. At the same time, I don't want to do this to all the columns, just the ones that needed. That is pretty much the difficulty I have. – ruben Sep 11 '18 at 14:35

0 Answers0