'generating continuous 'id' field in a column for all dataframes where I have a list of data frames

I have a list of 4/5 data frames with a blank column 'id', I want to generate a cumulative sequence across these data frames.

I tried something like this but its not working. f is my list of data frames

for i in range(1,len(f)):
    print(f[1]['id'])
    for  row in f[i]['id']: 
        f[i]=f[i].assign(id=numpy.arange(1,len(f)+1))

I want an output data frames like f[0]:

id table
1 abc
2 def

f[1]:

id table
3 abc
4 def

f[2]:

id table
5 abc
6 def

so on..

Please help.New to python



Solution 1:[1]

A simple loop approach could be:

dfs = [df1, df2]

start = 0
for d in dfs: 
    stop = start + len(d)
    d['id'] = range(start, stop)
    start = stop

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mozway