0

I have loaded a multiindex matrix from excel to a panda dataframe.

    df=pd.read_excel("filename.xlsx",sheet_name=sheet,header=1,index_col=[0,1,2],usecols="B:AZ")

The dataframe has three index colums and one header, so it has 4 indices. Part of the dataframe looks like this:

picture of part of dataframe

When I want to show a particular value, it works like this:

df[index1][index2][index3][index4]

I now want to change certain values in the dataframe. After searching through different forums for a while, it seemed like df.at would be the right method to do this. So I tried this:

df.at[index1,index2,index3,index4]=10 (or any random value)

but I got a ValueError: Not enough indexers for scalar access (setting)!. I also tried different orders for the indices inside the df.at-Brackets.

Any help on this would be much appreciated!

1 Answer 1

0

It seems you need something like that:

df.loc[('Kosten','LKW','Sofia'),'Ruse']=10
Sign up to request clarification or add additional context in comments.

2 Comments

That is exactly what I needed, thank you very much!
always glad to help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.