1

I'm trying to "refresh" the indices of my DataFrame. I'm trying:

df3 = df2.reindex()
df3.head()

But this still gives me:

        Dose
13539.0 1.0
13539.0 2.0
13539.0 5.0
13539.0 3.0
13539.0 4.0

I need to keep the "Dose" column in the same order, but make its indices 0 -> len(Dose).

In other words, my desired output is:

    Dose
0   1.0
1   2.0
2   5.0
3   3.0
4   4.0

Clearly I've pre-processed something to mess this up, but I'd appreciate any insight as to how I can amend it :-)

0

3 Answers 3

6
df3.reset_index(drop=True, inplace=True)

When you reset the index, a new sequential index is used. Normally the old index is added as a column, but you can use the drop parameter to avoid that.

Refer to this Pandas documentation: pandas.DataFrame.reset_index()

Sign up to request clarification or add additional context in comments.

Comments

1

You might want to lookup the documentation for reset_index. In your case:

df3.reset_index(drop=True)

Comments

0

This solution does the job...

df2 = df2.reset_index()
df2 = df2['Dose']

1 Comment

df2 = df2['Dose']??? That's a Series, not a df. What does that have to do with the problem anyway? But the first line is great; that's the solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.