I have a dataframe
df = pd.DataFrame({
'Col1': ['abc', 'qrt', 130, 200, 190, 210],
'Col2': ['xyz','tuv', 130, 200, 190, 210],
'Col3': ['pqr', 'set', 130, 200, 190, 210],})
I wish to take the first two rows of the dataframe, merge them separated by a hyphen and convert them into a new header. I tried
df.columns = np.concatenate(df.iloc[0], df.iloc[1])
df.columns = new_header
But that does not seem to work. The output should look like
df = pd.DataFrame({
'abc_qrt': [ 130, 200, 190, 210],
'xyz_tuv': [130, 200, 190, 210],
'pqr_set': [ 130, 200, 190, 210],})