diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 64e3d60e1fe14..40f2761b44dea 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -3093,10 +3093,11 @@ def astype(self, dtype, copy=True, raise_on_error=True, **kwargs): 'invoked on Series and DataFrames. A single dtype must be ' 'specified when invoked on a Panel.' ) - for col_name in dtype.keys(): - if col_name not in self: - raise KeyError('Only a column name can be used for the ' - 'key in a dtype mappings argument.') + if raise_on_error: + for col_name in dtype.keys(): + if col_name not in self: + raise KeyError('Only a column name can be used for the ' + 'key in a dtype mappings argument.') from pandas import concat results = [] for col_name, col in self.iteritems():