擅长:python、mysql、java
<p>在您的数据中,我认为所有数据都是字符串,但是如果要排除datetimes列,请使用<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.select_dtypes.html" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>def clean(text):
return text.str.lower().str.replace('[^A-Za-z0-9]', '')
#filter only object columns
mask = df.dtypes == 'object'
#filter Text columns if possible
#mask = df.columns.startswith('Text')
df.loc[:, mask] = df.loc[:, mask].apply(clean)
</code></pre>