bigframes.pandas.DataFrame.replace#
- DataFrame.replace(to_replace:Any,value:Any=None,*,regex:bool=False)[source]#
Replace values given into_replace withvalue.
Values of the Series/DataFrame are replaced with other values dynamically.This differs from updating with
.locor.iloc, which requireyou to specify a location to update with some value.Examples:
>>>importbigframes.pandasasbpd>>>df=bpd.DataFrame({...'int_col':[1,1,2,3],...'string_col':["a","b","c","b"],...})
Using scalarto_replace andvalue:
>>>df.replace("b","e") int_col string_col0 1 a1 1 e2 2 c3 3 e[4 rows x 2 columns]
Using dictionary:
>>>df.replace({"a":"e",2:5}) int_col string_col0 1 e1 1 b2 5 c3 3 b[4 rows x 2 columns]
Using regex:
>>>df.replace("[ab]","e",regex=True) int_col string_col0 1 e1 1 e2 2 c3 3 e[4 rows x 2 columns]
- Parameters:
to_replace (str,regex,list,int,float orNone) – How to find the values that will be replaced.numeric: numeric values equal toto_replace will be replaced withvaluestr: string exactly matchingto_replace will be replaced withvalueregex: regexs matchingto_replace will be replaced with`value`list of str, regex, or numeric:First, ifto_replace andvalue are both lists, theymust be the same length.Second, if
regex=Truethen all of the strings inbothlists will be interpreted as regexs otherwise they will matchdirectly. This doesn’t matter much forvalue since thereare only a few possible substitution regexes you can use.str, regex and numeric rules apply as above.value (scalar,default None) – Value to replace any values matchingto_replace with.For a DataFrame a dict of values can be used to specify whichvalue to use for each column (columns not in the dict will not befilled). Regular expressions, strings and lists or dicts of suchobjects are also allowed.
regex (bool,default False) – Whether to interpretto_replace and/orvalue as regularexpressions. If this is
Truethento_replacemust be astring.
- Returns:
Object after replacement.
- Return type: