【发布时间】:2019-10-07 07:23:27
【问题描述】:
我有这种方法,我只需要将其应用于'float32' 的列而不是所有列。
def preprocess(self, dataframe):
if self._means is None:
self._means = np.mean(dataframe, axis=0)
if self._stds is None:
self._stds = np.std(dataframe, axis=0)
if not self._stds.all():
raise ValueError('At least one column has std deviation of 0.')
return (dataframe - self._means) / self._stds
我收集这样的类型,但正在寻找 Pythonic 的方式来做到这一点:
dtypes = list(zip(dataframe.dtypes.index, map(str, dataframe.dtypes)))
# Normalize numeric columns.
for column, dtype in dtypes:
if dtype == 'float32':
【问题讨论】:
-
这有帮助吗? 38185759