添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
  • pandas.Series.is_unique
  • pandas.Series.is_monotonic_increasing
  • pandas.Series.is_monotonic_decreasing
  • pandas.Series.value_counts
  • pandas.Series.align
  • pandas.Series.case_when
  • pandas.Series.drop
  • pandas.Series.droplevel
  • pandas.Series.drop_duplicates
  • pandas.Series.duplicated
  • pandas.Series.equals
  • pandas.Series.first
  • pandas.Series.head
  • pandas.Series.idxmax
  • pandas.Series.idxmin
  • pandas.Series.isin
  • pandas.Series.last
  • pandas.Series.reindex
  • pandas.Series.reindex_like
  • pandas.Series.rename
  • pandas.Series.rename_axis
  • pandas.Series.reset_index
  • pandas.Series.sample
  • pandas.Series.set_axis
  • pandas.Series.take
  • pandas.Series.tail
  • pandas.Series.truncate
  • pandas.Series.where
  • pandas.Series.mask
  • pandas.Series.add_prefix
  • pandas.Series.add_suffix
  • pandas.Series.filter
  • pandas.Series.backfill
  • pandas.Series.bfill
  • pandas.Series.dropna
  • pandas.Series.ffill
  • pandas.Series.fillna
  • pandas.Series.interpolate
  • pandas.Series.isna
  • pandas.Series.isnull
  • pandas.Series.notna
  • pandas.Series.notnull
  • pandas.Series.pad
  • pandas.Series.replace
  • pandas.Series.argsort
  • pandas.Series.argmin
  • pandas.Series.argmax
  • pandas.Series.reorder_levels
  • pandas.Series.sort_values
  • pandas.Series.sort_index
  • pandas.Series.swaplevel
  • pandas.Series.unstack
  • pandas.Series.explode
  • pandas.Series.searchsorted
  • pandas.Series.ravel
  • pandas.Series.repeat
  • pandas.Series.squeeze
  • pandas.Series.view
  • pandas.Series.compare
  • pandas.Series.update
  • pandas.Series.asfreq
  • pandas.Series.asof
  • pandas.Series.shift
  • pandas.Series.first_valid_index
  • pandas.Series.last_valid_index
  • pandas.Series.resample
  • pandas.Series.tz_convert
  • pandas.Series.tz_localize
  • pandas.Series.at_time
  • pandas.Series.between_time
  • pandas.Series.str
  • pandas.Series.cat
  • pandas.Series.dt
  • pandas.Series.sparse
  • pandas.DataFrame.sparse
  • pandas.Index.str
  • pandas.Series.dt.date
  • pandas.Series.dt.time
  • pandas.Series.dt.timetz
  • pandas.Series.dt.year
  • pandas.Series.dt.month
  • pandas.Series.dt.day
  • pandas.Series.dt.hour
  • pandas.Series.dt.minute
  • pandas.Series.dt.second
  • pandas.Series.dt.microsecond
  • pandas.Series.dt.nanosecond
  • pandas.Series.dt.dayofweek
  • pandas.Series.dt.day_of_week
  • pandas.Series.dt.weekday
  • pandas.Series.dt.dayofyear
  • pandas.Series.dt.day_of_year
  • pandas.Series.dt.days_in_month
  • pandas.Series.dt.quarter
  • pandas.Series.dt.is_month_start
  • pandas.Series.dt.is_month_end
  • pandas.Series.dt.is_quarter_start
  • pandas.Series.dt.is_quarter_end
  • pandas.Series.dt.is_year_start
  • pandas.Series.dt.is_year_end
  • pandas.Series.dt.is_leap_year
  • pandas.Series.dt.daysinmonth
  • pandas.Series.dt.days_in_month
  • pandas.Series.dt.tz
  • pandas.Series.dt.freq
  • pandas.Series.dt.unit
  • pandas.Series.dt.isocalendar
  • pandas.Series.dt.to_period
  • pandas.Series.dt.to_pydatetime
  • pandas.Series.dt.tz_localize
  • pandas.Series.dt.tz_convert
  • pandas.Series.dt.normalize
  • pandas.Series.dt.strftime
  • pandas.Series.dt.round
  • pandas.Series.dt.floor
  • pandas.Series.dt.ceil
  • pandas.Series.dt.month_name
  • pandas.Series.dt.day_name
  • pandas.Series.dt.as_unit
  • pandas.Series.dt.qyear
  • pandas.Series.dt.start_time
  • pandas.Series.dt.end_time
  • pandas.Series.dt.days
  • pandas.Series.dt.seconds
  • pandas.Series.dt.microseconds
  • pandas.Series.dt.nanoseconds
  • pandas.Series.dt.components
  • pandas.Series.dt.unit
  • pandas.Series.dt.to_pytimedelta
  • pandas.Series.dt.total_seconds
  • pandas.Series.dt.as_unit
  • pandas.Series.str.capitalize
  • pandas.Series.str.casefold
  • pandas.Series.str.cat
  • pandas.Series.str.center
  • pandas.Series.str.contains
  • pandas.Series.str.count
  • pandas.Series.str.decode
  • pandas.Series.str.encode
  • pandas.Series.str.endswith
  • pandas.Series.str.extract
  • pandas.Series.str.extractall
  • pandas.Series.str.find
  • pandas.Series.str.findall
  • pandas.Series.str.fullmatch
  • pandas.Series.str.get
  • pandas.Series.str.index
  • pandas.Series.str.join
  • pandas.Series.str.len
  • pandas.Series.str.ljust
  • pandas.Series.str.lower
  • pandas.Series.str.lstrip
  • pandas.Series.str.match
  • pandas.Series.str.normalize
  • pandas.Series.str.pad
  • pandas.Series.str.partition
  • pandas.Series.str.removeprefix
  • pandas.Series.str.removesuffix
  • pandas.Series.str.repeat
  • pandas.Series.str.replace
  • pandas.Series.str.rfind
  • pandas.Series.str.rindex
  • pandas.Series.str.rjust
  • pandas.Series.str.rpartition
  • pandas.Series.str.rstrip
  • pandas.Series.str.slice
  • pandas.Series.str.slice_replace
  • pandas.Series.str.split
  • pandas.Series.str.rsplit
  • pandas.Series.str.startswith
  • pandas.Series.str.strip
  • pandas.Series.str.swapcase
  • pandas.Series.str.title
  • pandas.Series.str.translate
  • pandas.Series.str.upper
  • pandas.Series.str.wrap
  • pandas.Series.str.zfill
  • pandas.Series.str.isalnum
  • pandas.Series.str.isalpha
  • pandas.Series.str.isdigit
  • pandas.Series.str.isspace
  • pandas.Series.str.islower
  • pandas.Series.str.isupper
  • pandas.Series.str.istitle
  • pandas.Series.str.isnumeric
  • pandas.Series.str.isdecimal
  • pandas.Series.str.get_dummies
  • pandas.Series.cat.categories
  • pandas.Series.cat.ordered
  • pandas.Series.cat.codes
  • pandas.Series.cat.rename_categories
  • pandas.Series.cat.reorder_categories
  • pandas.Series.cat.add_categories
  • pandas.Series.cat.remove_categories
  • pandas.Series.cat.remove_unused_categories
  • pandas.Series.cat.set_categories
  • pandas.Series.cat.as_ordered
  • pandas.Series.cat.as_unordered
  • pandas.Series.sparse.npoints
  • pandas.Series.sparse.density
  • pandas.Series.sparse.fill_value
  • pandas.Series.sparse.sp_values
  • pandas.Series.sparse.from_coo
  • pandas.Series.sparse.to_coo
  • pandas.Series.list.flatten
  • pandas.Series.list.len
  • pandas.Series.list.__getitem__
  • pandas.Series.struct.dtypes
  • pandas.Series.struct.field
  • pandas.Series.struct.explode
  • pandas.Flags
  • pandas.Series.attrs
  • pandas.Series.plot
  • pandas.Series.plot.area
  • pandas.Series.plot.bar
  • pandas.Series.plot.barh
  • pandas.Series.plot.box
  • pandas.Series.plot.density
  • pandas.Series.plot.hist
  • pandas.Series.plot.kde
  • pandas.Series.plot.line
  • pandas.Series.plot.pie
  • pandas.Series.hist
  • pandas.Series.to_pickle
  • pandas.Series.to_csv
  • pandas.Series.to_dict
  • pandas.Series.to_excel
  • pandas.Series.to_frame
  • pandas.Series.to_xarray
  • pandas.Series.to_hdf
  • pandas.Series.to_sql
  • pandas.Series.to_json
  • pandas.Series.to_string
  • pandas.Series.to_clipboard
  • pandas.Series.to_latex
  • pandas.Series.to_markdown
  • DataFrame
  • pandas arrays, scalars, and data types
  • Index objects
  • Date offsets
  • Window
  • GroupBy
  • Resampling
  • Style
  • Plotting
  • Options and settings
  • Extensions
  • Testing
  • Missing values
  • Series.str. replace ( pat , repl , n = -1 , case = None , flags = 0 , regex = False ) [source] #

    Replace each occurrence of pattern/regex in the Series/Index.

    Equivalent to str.replace() or re.sub() , depending on the regex value.

    Parameters :
    pat str or compiled regex

    String can be a character sequence or regular expression.

    repl str or callable

    Replacement string or a callable. The callable is passed the regex match object and must return a replacement string to be used. See re.sub() .

    n int, default -1 (all)

    Number of replacements to make from start.

    case bool, default None

    Determines if replace is case sensitive:

  • If True, case sensitive (the default if pat is a string)

  • Set to False for case insensitive

  • Cannot be set if pat is a compiled regex.

  • flags int, default 0 (no flags)

    Regex module flags, e.g. re.IGNORECASE. Cannot be set if pat is a compiled regex.

    regex bool, default False

    Determines if the passed-in pattern is a regular expression:

  • If True, assumes the passed-in pattern is a regular expression.

  • If False, treats the pattern as a literal string

  • Cannot be set to False if pat is a compiled regex or repl is a callable.

  • Returns :
    Series or Index of object

    A copy of the object with all matching occurrences of pat replaced by repl .

    Raises :
    ValueError
    • if regex is False and repl is a callable or pat is a compiled regex

    • if pat is a compiled regex and case or flags is set

    • Notes

      When pat is a compiled regex, all flags should be included in the compiled regex. Use of case , flags , or regex=False with a compiled regex will raise an error.

      Examples

      When pat is a string and regex is True, the given pat is compiled as a regex. When repl is a string, it replaces matching regex patterns as with re.sub() . NaN value(s) in the Series are left as is:

      >>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f.', 'ba', regex=True)
      0    bao
      1    baz
      2    NaN
      dtype: object
      

      When pat is a string and regex is False, every pat is replaced with repl as with str.replace():

      >>> pd.Series(['f.o', 'fuz', np.nan]).str.replace('f.', 'ba', regex=False)
      0    bao
      1    fuz
      2    NaN
      dtype: object
      

      When repl is a callable, it is called on every pat using re.sub(). The callable should expect one positional argument (a regex object) and return a string.

      To get the idea:

      >>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f', repr, regex=True)
      0    <re.Match object; span=(0, 1), match='f'>oo
      1    <re.Match object; span=(0, 1), match='f'>uz
      2                                            NaN
      dtype: object
      

      Reverse every lowercase alphabetic word:

      >>> repl = lambda m: m.group(0)[::-1]
      >>> ser = pd.Series(['foo 123', 'bar baz', np.nan])
      >>> ser.str.replace(r'[a-z]+', repl, regex=True)
      0    oof 123
      1    rab zab
      2        NaN
      dtype: object
      

      Using regex groups (extract second group and swap case):

      >>> pat = r"(?P<one>\w+) (?P<two>\w+) (?P<three>\w+)"
      >>> repl = lambda m: m.group('two').swapcase()
      >>> ser = pd.Series(['One Two Three', 'Foo Bar Baz'])
      >>> ser.str.replace(pat, repl, regex=True)
      0    tWO
      1    bAR
      dtype: object
      

      Using a compiled regex with flags

      >>> import re
      >>> regex_pat = re.compile(r'FUZ', flags=re.IGNORECASE)
      >>> pd.Series(['foo', 'fuz', np.nan]).str.replace(regex_pat, 'bar', regex=True)
      0    foo
      1    bar
      2    NaN
      dtype: object