<p>我当前有以下数据帧:</p>
<pre><code>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
</code></pre>
<p>我正在尝试返回一个新的数据帧,其中只保留了海柱和以后的数据帧:</p>
<pre><code>df1
5 6
0 Sea NaN
1 light medium
2 15 14
3 18 29
4 19 42
</code></pre>
<p>我觉得我很熟悉我的代码:</p>
<pre><code>for i in range(len(df.columns)):
if pd.Series.any(df.iloc[:,i].str.contains(pat="Sea")):
xyz = df.columns[i] #This is the piece of code I am having trouble with
df = df.loc[:,[xyz:??]]
</code></pre>
<p>从本质上说,我想返回单词“Sea”所在的列索引,然后根据该索引的长度创建一个新的dataframe。希望这个解释有道理,并感谢任何帮助</p>