Home > Net >  How to create ordered numbers?
How to create ordered numbers?

Time:12-30

I want to create two columns (row, column) in a data frame that contains ordered numbers based on the value. For example the value is 128, Something like that: enter image description here

so the number of rows will be 128 * 128, if 256 then 256*256 and so on

CodePudding user response:

You can use a nested for loop:

x,y = [],[]
for i in range(1,129):
    for j in range(1,129):
        x.append(j)
        y.append(i)
df = pd.DataFrame({'x':x, 'y':y})

Result:

         x    y
0        1    1
1        2    1
2        3    1
3        4    1
4        5    1
...    ...  ...
16379  124  128
16380  125  128
16381  126  128
16382  127  128
16383  128  128
  • Related