Can sub-columns be created in a pandas data frame?

后端 未结 3 1367
梦毁少年i
梦毁少年i 2021-02-06 17:43

Data frame

I am working with a data frame in Jupyter Notebooks and I am having some difficulty with it. The data frame consists of locations and these are represented by

3条回答
  •  梦谈多话
    2021-02-06 17:51

    You can read an Excel file with 2 headers (2 levels of columns).

       df = pd.read_excel(
            sourceFilePath,
            index_col = [0],
            header = [0, 1]
        )
    

    You can reshape your df like this in order to keep just 1 header (its easier to work with only 1 header):

    df = df.stack([0,1], dropna=False).to_frame('Valeur').reset_index()
    

提交回复
热议问题