Is there any equivalent pandas.DataFrame.reset_index() that works with columns and can handle the case of duplicate column names? I want it to throw away column names and return the default index of 0.1,2 .. for columns. (Methods like df.rename or df.reindex_axis do not work if I have duplicate column names.)
Input Example:
pd.DataFrame(np.random.rand(5, 3), columns = ['A', 'A', 'B']) AAB 0 0.5 0.3 0.9 1 0.7 0.9 0.3 2 0.9 0.4 0.8 3 0.6 0.2 0.9 4 0.7 0.4 0.6
Expected Result:
0 1 2 0 0.8 0.1 0.2 1 0.4 0.2 0.4 2 0.3 0.3 0.4 3 0.4 0.1 0.8 4 1.0 0.9 0.9
source share