Pandas: How to access the value of the index Pandas: How to access the value of the index pandas pandas

Pandas: How to access the value of the index


df["idx1_mod"] = df.index.get_level_values(0).values + 100


Try this:

for idx in range(len(df)):    df['idx1_mod'][idx] = df.index[idx][0] + 100 


You can use drop=False when setting the index to preserve your keys as columns. This should work:

df.set_index(keys=['idx1','idx2'], inplace=True, drop=False)df['idx1_mod'] = df['idx'] + 100