I would like to create a df_D from the given input df using the entry 'Start' as my reference for both the row and column indexing.
I do not want to use the column names A,B, C etc.
Instead, I wish to use indexing as the sequence is always the first 3 columns from 'START' and the last 3 columns, ie something like n,n+1,n+2, n+5,n+6,n+7
Input:
df = pd.DataFrame({'A':['jfgh',23,'Ndfg',34,0,56],'B':['jfgh',23,'START',34,0,56], 'C':['cvb',7,'dsfgA',65,47,3],'D':['rrb',7,'gfd',3,0,7],'E':['dfg',7,'gfd',5,12,1],'F':['dfg',7,'sdfA',5,0,4],'G':['dfg',7,'sdA',5,8,9],'H':['dfg',7,'gfA',5,0,8],'I':['dfg',7,'sdfA',5,7,23]})
Output:
A B C D E F G H I
0 jfgh jfgh cvb rrb dfg dfg dfg dfg dfg
1 23 23 7 7 7 7 7 7 7
2 Ndfg START dsfgA gfd gfd sdfA sdA gfA sdfA
3 34 34 65 3 5 5 5 5 5
4 0 0 47 0 12 0 8 0 7
5 56 56 3 7 1 4 9 8 23
Desired Output: df_D Created manually
B C D G H I
0 0 47 0 8 0 7
1 56 3 7 9 8 23
Attempt 1:
for index in range(len(df)):
if str(df.loc[index,'C']).startswith('START'):
df_D = df.iloc[index+1:len(df), [1,2,3,6,7,8]]
break
Resulting Output:
Empty DataFrame
Columns: [B, C, D, G, H, I]
Index: []
Where have I gone wrong?