Issue
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
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
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.