concise way of flattening multiindex columns
Since version 0.24.0, you can just use to_flat_index.
out.columns = [f"{x}_{y}" for x, y in out.columns.to_flat_index()]
B_mean B_std C_median
A
1 0.779592 0.137168 0.583211
2 0.158010 0.229234 0.550383
3 0.186771 0.150575 0.313409
You can do a map
join
with columns
out.columns = out.columns.map('_'.join)
out
Out[23]:
B_mean B_std C_median
A
1 0.204825 0.169408 0.926347
2 0.362184 0.404272 0.224119
3 0.533502 0.380614 0.218105
For some reason (when the column contain int) I like this way better
out.columns.map('{0[0]}_{0[1]}'.format)
Out[27]: Index(['B_mean', 'B_std', 'C_median'], dtype='object')