0

I am importing an excel sheet that has two header rows: first row is a common name and second row is column names. I want to prefix each column by the row1 common name.

enter image description here

My code:

df = pd.read_excel('example.xlsx', skiprows=None)

Expected output:

df.columns = 

['Other Standard_SAIDI With MED', ...]
Mainland
  • 4,110
  • 3
  • 25
  • 56
  • 1
    This can help: https://stackoverflow.com/questions/41005577/python-pandas-two-rows-as-column-headers, https://stackoverflow.com/questions/37369317/how-do-i-change-or-access-pandas-multiindex-column-headers – Luis Alejandro Vargas Ramos Sep 24 '22 at 02:42
  • Hi, unless there is more to know that what the image shows, you could set `skiprows=0` and then do `df.columns = [f"Other Standard_{col}" for col in df.columns]` – Laurent Sep 25 '22 at 06:43

0 Answers0