Returns the a string where the occurrences of the old_value substrings are replaced by the new_value substring. Args: count: Maximum number of occurrences to replace. When set to -1, replaces all occurrences. Defaults to -1. Returns:
(
self,
old_value: expr.ColumnExpression | str,
new_value: expr.ColumnExpression | str,
count: expr.ColumnExpression | int = -1,
/,
)
| 193 | ) |
| 194 | |
| 195 | def replace( |
| 196 | self, |
| 197 | old_value: expr.ColumnExpression | str, |
| 198 | new_value: expr.ColumnExpression | str, |
| 199 | count: expr.ColumnExpression | int = -1, |
| 200 | /, |
| 201 | ) -> expr.ColumnExpression: |
| 202 | """Returns the a string where the occurrences of the old_value substrings are |
| 203 | replaced by the new_value substring. |
| 204 | |
| 205 | Args: |
| 206 | count: Maximum number of occurrences to replace. When set to -1, replaces |
| 207 | all occurrences. Defaults to -1. |
| 208 | |
| 209 | Returns: |
| 210 | The new string where old_value is replaced by new_value |
| 211 | |
| 212 | Example: |
| 213 | |
| 214 | >>> import pathway as pw |
| 215 | >>> table = pw.debug.table_from_markdown( |
| 216 | ... ''' |
| 217 | ... | name |
| 218 | ... 1 | Alice |
| 219 | ... 2 | Bob |
| 220 | ... 3 | CAROLE |
| 221 | ... 4 | david |
| 222 | ... 5 | Edward |
| 223 | ... ''' |
| 224 | ... ) |
| 225 | >>> table += table.select(name_replace=table.name.str.replace("d","Z")) |
| 226 | >>> pw.debug.compute_and_print(table, include_id=False) |
| 227 | name | name_replace |
| 228 | Alice | Alice |
| 229 | Bob | Bob |
| 230 | CAROLE | CAROLE |
| 231 | Edward | EZwarZ |
| 232 | david | ZaviZ |
| 233 | >>> table = pw.debug.table_from_markdown( |
| 234 | ... ''' |
| 235 | ... | value | old | new | count |
| 236 | ... 1 | Scaciscics | c | t | 3 |
| 237 | ... 2 | yelliwwiid | i | o | 2 |
| 238 | ... ''' |
| 239 | ... ) |
| 240 | >>> table = table.select( |
| 241 | ... pw.this.value, |
| 242 | ... value_replace=pw.this.value.str.replace( |
| 243 | ... pw.this.old, pw.this.new, pw.this.count |
| 244 | ... ) |
| 245 | ... ) |
| 246 | >>> pw.debug.compute_and_print(table, include_id=False) |
| 247 | value | value_replace |
| 248 | Scaciscics | Statistics |
| 249 | yelliwwiid | yellowwoid |
| 250 | """ |
| 251 | |
| 252 | return expr.MethodCallExpression( |