0

I have a series of dataframes in a dict.

type(mydict[0])
pandas.core.frame.DataFrame

print(dict[0])

          0         1         2
0  0.278735  0.609862  0.085823
1  0.836997  0.739635  0.866059
2  0.691271  0.377185  0.225146

print(dict[1])

          0         1         2
3  0.435280  0.700900  0.700946
4  0.796487  0.018688  0.700566
5  0.900749  0.764869  0.253200

How can I change the value of the index of dict[1] to such that it looks like this

print(dict[0])

          0         1         2
0  0.278735  0.609862  0.085823
1  0.836997  0.739635  0.866059
2  0.691271  0.377185  0.225146

print(dict[1])

          0         1         2
0  0.435280  0.700900  0.700946
1  0.796487  0.018688  0.700566
2  0.900749  0.764869  0.253200

1 Answer 1

2

Try:

mydict[1].reset_index(drop=True, inplace=True)
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks This works on my simple example. It unfortunately doesn't seem to work when dict[1] is a multiIndex dataframe with 2 levels where the index I'm trying to reset is at level=1. I tried for i in df: df[i] = self.data[i].reset_index(level=1, drop=True, inplace=True) but print(mydict[1]) produces None Good answer. Over simplified example on my part.
inplace=True will make the function returning None. Don't assign the function result
Awesome! Thanks. Makes perfect sense.

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.