In [37]: df = pd.DataFrame([[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]]) In [38]: df2 = pd.concat([df, df]) In [39]: df2.reset_index() Out[39]: index 0 1 2 3 0 0 1 2 3 4 1 1 2 3 4 5 2 2 3 4 5 6 3 0 1 2 3 4 4 1 2 3 4 5 5 2 3 4 5 6
My problem is that how can I reset_index
without adding a new column index
?
If you want to keep the original index as a column, use reset_index() to reassign the index to a sequential number starting from 0 . You can change the index to a different column by using set_index() after reset_index() . See also the following article for reset_index() .
To reset the index in pandas, you simply need to chain the function . reset_index() with the dataframe object. On applying the . reset_index() function, the index gets shifted to the dataframe as a separate column.
The reset_index() function is used to generate a new DataFrame or Series with the index reset. For a Series with a MultiIndex, only remove the specified levels from the index. Removes all levels by default. Just reset the index, without inserting it as a column in the new DataFrame.
You can use the drop=True
option in reset_index()
. See here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With