MCPcopy Index your code
hub / github.com/pathwaycom/pathway / replace

Method replace

python/pathway/internals/expressions/string.py:195–272  ·  view source on GitHub ↗

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,
        /,
    )

Source from the content-addressed store, hash-verified

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(

Callers 15

parse_cited_responseFunction · 0.80
_convert_pptx_to_pdfFunction · 0.80
_get_jmespath_filterFunction · 0.80
parse_visual_dataMethod · 0.80
_clean_text_linesMethod · 0.80
_remove_empty_spaceMethod · 0.80
get_file_nameFunction · 0.80
get_file_nameFunction · 0.80
schema_from_pandasFunction · 0.80
with_typesMethod · 0.80
update_propertiesMethod · 0.80
with_updated_originMethod · 0.80

Calls 2

applyMethod · 0.80
to_engineMethod · 0.45

Tested by 15

get_file_nameFunction · 0.64
get_file_nameFunction · 0.64
replace_some_charsFunction · 0.64
test_jsonlines_readingFunction · 0.64
test_strftimeFunction · 0.64
_apply_mssql_changeFunction · 0.64