Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/6003#discussion_r30088189
--- Diff: python/pyspark/sql/dataframe.py ---
@@ -896,6 +900,76 @@ def fillna(self, value, subset=None):
return DataFrame(self._jdf.na().fill(value,
self._jseq(subset)), self.sql_ctx)
+ def replace(self, to_replace, value, subset=None):
+ """Returns a new :class:`DataFrame` replacing a value with another
value.
+
+ :param to_replace: int, long, float, string, or list.
+ Value to be replaced.
+ The replacement value must be an int, long, float, or string.
+ :param value: int, long, float, string, or list.
+ Value to use to replace holes.
+ The replacement value must be an int, long, float, or string.
+ :param subset: optional list of column names to consider.
+ Columns specified in subset that do not have matching data
type are ignored.
+ For example, if `value` is a string, and subset contains a
non-string column,
+ then the non-string column is simply ignored.
+ >>> df4.replace(10, 20).show()
+ +----+------+-----+
+ | age|height| name|
+ +----+------+-----+
+ | 20| 80|Alice|
+ | 5| null| Bob|
+ |null| null| Tom|
+ |null| null| null|
+ +----+------+-----+
+
+ >>> df4.replace(['Alice', 'Bob'], ['A', 'B'], 'name').show()
+ +----+------+----+
+ | age|height|name|
+ +----+------+----+
+ | 10| 80| A|
+ | 5| null| B|
+ |null| null| Tom|
+ |null| null|null|
+ +----+------+----+
+ """
+ if not isinstance(to_replace, (float, int, long, basestring, list,
tuple)):
--- End diff --
the error handling are pretty nice!
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]