0

i have a daframe with à multiindex column with 1 short name and 1 long name

df = pd.DataFrame({('Code géographique', 'CODGEO'): {0: 1001},
                   ('Région', 'REG'): {0: 84},
                   ('Département', 'DEP'): {0: 1},
                   ('Libellé géographique', 'LIBGEO'): {0: "L'Abergement-Clémenciat"},
                   ('Population en 2020 (princ)', 'P20_POP'): {0: 806}})

i want to select columns based on short name but i want to keep the multiindex structure. how can i do

columns_to_keep = ['CODGEO', 'REG', 'DEP']
steboc
  • 1,161
  • 1
  • 7
  • 17

0 Answers0