Pandas create row number - but not as an index

后端 未结 1 1786
无人共我
无人共我 2021-01-26 23:13

I want to create a row number series - but not override my date index.

I can do it with a loop but I think there must be an easier way?

_cnt = [ ]

for i         


        
相关标签:
1条回答
  • 2021-01-26 23:51

    Probably the easiest way:

    df['row'] = range(len(df))
    
    >>> df
              0         1
    0  0.444965  0.993382
    1  0.001578  0.174628
    2  0.663239  0.072992
    3  0.664612  0.291361
    4  0.486449  0.528354
    >>> df['row'] = range(len(df))
    >>> df
              0         1  row
    0  0.444965  0.993382    0
    1  0.001578  0.174628    1
    2  0.663239  0.072992    2
    3  0.664612  0.291361    3
    4  0.486449  0.528354    4
    
    0 讨论(0)
提交回复
热议问题