pythonpandasdataframenp

Change pd.Dataframe automatic numbering (np.outer, stack)


Via import from Data and creating a DataFrame with np.outer i got:

enter image description here

How can i change the values of the counting of the rows (0 1 2)? I want them to be 0.0, 0.1, 0.2 because I need them for further calculations. (I then use .stack and there i need 0.0,0.1,0.2 for the rows and 0,1,2 for the columns).

Im not sure how, because the numbering of the rows (0-2) and columns (0-4) were generated automatically?

(I have little to non programming skills and trying my best:))

Thanks


I tried insertig a extra row with 0.0, 0.1, 0.2:

enter image description here

But the numbering 0-2 is still there and is used if I try .stack:

enter image description here

Thats not what i need -> I want to replace the row-numbering


Solution

  • IIUC, you can modify the range index like:

    df.index /= 10
    print(df)
    
    # Output
            0     1       2     3     4
    0.0   2.0   4.0  0.0010   6.0   8.0
    0.1  23.0  46.0  0.0115  69.0  92.0
    0.2   3.0   6.0  0.0015   9.0  12.0