I have three dataframes of different length. I am combining them into one dataframe for saving it. Now, I want to retrieve individual dataframe data from the combined dataframe using index. A sample of my problem is given below:
df1 =
data
0 10
1 20
df2 =
data
0 100
1 200
2 300
df3 =
data
0 1000
1 2000
2 3000
3 4000
combdf = pd.concat ([df1,df2,df3],ignore_index=True])
combdf =
data
0 10
1 20
2 100
3 200
4 300
5 1000
6 2000
7 3000
8 4000
I want to retrieve data of individual data frames from combdf. My code:
data_len = [len(df1),len(df2),len(df3)]
for k in range(0,len(data_len),1):
if k==0:
st_id = 0
else:
st_id = sum(data_len[:k])
ed_id = st_id+data_len[k]
print(combdf.iloc[st_id:ed_id])
Above code is working fine. Is there a better approach than this which does not use for loop?