[Python] Problem renaming index value in pandas multiindex series

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    Please consider this dataframe:

    temp = pd.DataFrame({'has_exclamation': {('automotive', 0.0): 99.1814132659203,
    ('automotive', np.nan): 0.8185867340796917,
    ('beauty_spa', 0.0): 99.8,
    ('beauty_spa', np.nan): 0.15384615384615385,
    ('beauty_spa', 1.0): 0.04615384615384615},
    'has_exclamation_end': {('automotive', 0.0): 99.1814132659203,
    ('automotive', np.nan): 0.8185867340796917,
    ('beauty_spa', 0.0): 99.83846153846154,
    ('beauty_spa', np.nan): 0.15384615384615385,
    ('beauty_spa', 1.0): 0.007692307692307693},
    'has_all_cap': {('automotive', 0.0): 98.88046226074395,
    ('automotive', np.nan): 0.8185867340796917,
    ('beauty_spa', 0.0): 99.56153846153846,
    ('beauty_spa', np.nan): 0.15384615384615385,
    ('beauty_spa', 1.0): 0.28461538461538466}})


    temp:

    [​IMG]

    To replace the NaNs with 'Missing' in the index, why does this not work?

    temp.rename(index={np.nan: 'Missing'}, level =1)

    Continue reading...

Compartilhe esta Página