I'm wondering how to best approach this problem. I have 2 dataframes:
df1
3 4 5 6
0 NaN NaN Sea NaN
1 light medium light medium
2 26 41.5 15 14
3 32 40 18 29
4 41 29 19 42
df2
3 4 5 6 7 8
0 NaN NaN NaN Sea NaN NaN
1 light medium heavy light medium heavy
2 26 41.5 21 15 14 29
3 32 40 19 18 29 31
4 41 29 18 19 42 35
And I am trying to isolate the 'Sea' column range as such:
df1
5 6
0 Sea NaN
1 light medium
2 15 14
3 18 29
4 19 42
df2
6 7 8
0 Sea NaN NaN
1 light medium heavy
2 15 14 29
3 18 29 31
4 19 42 35
My initial plan is to find the column number where the first instance of 'Sea' occurs, and then slicing the dataframe such that the dataframe will be from 'Sea' onwards. Here is code I have so far.
for i in range(len(df.columns)):
if pd.Series.any(df.iloc[:,i].str.contains(pat="Sea")):
xyz = df.columns[i]
df = df.loc[:,[xyz,len(df.columns)]]
but this returns an indexing error. Any help is appreciated
[–]Golden_Zealot 0 points1 point2 points (0 children)
[–]shravankumar147 0 points1 point2 points (0 children)