replace 替代值
replace(to_replace=None, value=None, inplace=False, limit=None, regex=False, method='pad') method of pandas.core.series.Series instance
Syntax: DataFrame.replace(to_replace=None, value=None, inplace=False, limit=None, regex=False, method=’pad’, axis=None)
Parameters:
to_replace : [str, regex, list, dict, Series, numeric, or None] pattern that we are trying to replace in dataframe.
value : Value to use to fill holes (e.g. 0), alternately a dict of values specifying which value to use for each column (columns not in the dict will not be filled). Regular expressions, strings and lists or dicts of such objects are also allowed.
inplace : If True, in place. Note: this will modify any other views on this object (e.g. a column from a DataFrame). Returns the caller if this is True.
limit : Maximum size gap to forward or backward fill
regex(正则表达式) : Whether to interpret to_replace and/or value as regular expressions. If this is True then to_replace must be a string. Otherwise, to_replace must be None because this parameter will be interpreted as a regular expression or a list, dict, or array of regular expressions.
method : Method to use when for replacement, when to_replace is a list.
Returns: filled : NDFrame
Example #1: Replace team “Boston Celtics” with “Omega Warrior” in the nba.csv file
Example #2: Replacing more than one value at a time. Using python list as an argument
Example #3: Replace the Nan value in the data frame with -99999 value
|
|