擅长:python、mysql、java
<p>也许你可以写一个简单的函数来实现。你知道吗</p>
<pre><code> def match_cut(df, to_match):
for col in df.columns:
if df[col].str.match(to_match).any():
return df.loc[:, col:]
return pd.DataFrame()
</code></pre>
<p>既然如此,<a href="https://stackoverflow.com/questions/45405814/returning-new-dataframe-from-column-range-pandas/45405856#45405856">cᴏʟᴅsᴘᴇᴇᴅ's answer</a>应该是首选,因为它避免了类似于此函数的列循环。你知道吗</p>
<hr/>
<pre><code>>>> match_cut(df, 'Sea')
5 6
0 Sea np.nan
1 light medium
2 15 14
3 18 29
4 19 42
</code></pre>