I have a dataframe as below
my_df = pd.DataFrame({
'Imp': [1,2,3,4,5,6,7,8,9,0],
'Apple': ['a','b','c','d','e','f','g','h','i','j']
})
print(my_df)
Imp Apple
0 1 a
1 2 b
2 3 c
3 4 d
4 5 e
5 6 f
6 7 g
7 8 h
8 9 i
9 0 j
Then i have a function as below. The intention of this function is to slice the original df based on some logic. Logic is not important here & the function runs fine.
The problem what i am facing is that i am not able to assign the sliced pieces of dataframe are assigned to the name 'df1','df2' ...
I have put in dfi = df.loc[0:i,] but this i am doing something incorrect this this very line & i am not able to figure out what.
Expected output is when I print (df1), i should get the first slice of that was created using this function. Can anyone help?
def func(df):
i=1
while len(df)!=0:
dfi=df.loc[0:i,]
df=df.loc[i:,].reset_index(drop=True)
i=i+1
if len(df)==0:
break