Series

Constructor

Series([data, index, dtype, name, copy, ...]) One-dimensional ndarray with axis labels (including time series).

Attributes

Axes
  • index: axis labels
Series.values Return Series as ndarray or ndarray-like
Series.dtype return the dtype object of the underlying data
Series.ftype return if the data is sparse|dense
Series.shape return a tuple of the shape of the underlying data
Series.nbytes return the number of bytes in the underlying data
Series.ndim return the number of dimensions of the underlying data,
Series.size return the number of elements in the underlying data
Series.strides return the strides of the underlying data
Series.itemsize return the size of the dtype of the item of the underlying data
Series.base return the base object if the memory of the underlying data is
Series.T return the transpose, which is by definition self
Series.memory_usage([index, deep]) Memory usage of the Series

Conversion

Series.astype(dtype[, copy, raise_on_error]) Cast object to input numpy.dtype
Series.copy([deep]) Make a copy of this objects data.
Series.isnull() Return a boolean same-sized object indicating if the values are null.
Series.notnull() Return a boolean same-sized object indicating if the values are not null.

Indexing, iteration

Series.get(key[, default]) Get item from object for given key (DataFrame column, Panel slice, etc.).
Series.at Fast label-based scalar accessor
Series.iat Fast integer location scalar accessor.
Series.ix A primarily label-location based indexer, with integer position fallback.
Series.loc Purely label-location based indexer for selection by label.
Series.iloc Purely integer-location based indexing for selection by position.
Series.__iter__() provide iteration over the values of the Series
Series.iteritems() Lazily iterate over (index, value) tuples

For more information on .at, .iat, .ix, .loc, and .iloc, see the indexing documentation.

Binary operator functions

Series.add(other[, level, fill_value, axis]) Addition of series and other, element-wise (binary operator add).
Series.sub(other[, level, fill_value, axis]) Subtraction of series and other, element-wise (binary operator sub).
Series.mul(other[, level, fill_value, axis]) Multiplication of series and other, element-wise (binary operator mul).
Series.div(other[, level, fill_value, axis]) Floating division of series and other, element-wise (binary operator truediv).
Series.truediv(other[, level, fill_value, axis]) Floating division of series and other, element-wise (binary operator truediv).
Series.floordiv(other[, level, fill_value, axis]) Integer division of series and other, element-wise (binary operator floordiv).
Series.mod(other[, level, fill_value, axis]) Modulo of series and other, element-wise (binary operator mod).
Series.pow(other[, level, fill_value, axis]) Exponential power of series and other, element-wise (binary operator pow).
Series.radd(other[, level, fill_value, axis]) Addition of series and other, element-wise (binary operator radd).
Series.rsub(other[, level, fill_value, axis]) Subtraction of series and other, element-wise (binary operator rsub).
Series.rmul(other[, level, fill_value, axis]) Multiplication of series and other, element-wise (binary operator rmul).
Series.rdiv(other[, level, fill_value, axis]) Floating division of series and other, element-wise (binary operator rtruediv).
Series.rtruediv(other[, level, fill_value, axis]) Floating division of series and other, element-wise (binary operator rtruediv).
Series.rfloordiv(other[, level, fill_value, ...]) Integer division of series and other, element-wise (binary operator rfloordiv).
Series.rmod(other[, level, fill_value, axis]) Modulo of series and other, element-wise (binary operator rmod).
Series.rpow(other[, level, fill_value, axis]) Exponential power of series and other, element-wise (binary operator rpow).
Series.combine(other, func[, fill_value]) Perform elementwise binary operation on two Series using given function
Series.combine_first(other) Combine Series values, choosing the calling Series’s values first.
Series.round([decimals]) Round each value in a Series to the given number of decimals.
Series.lt(other[, axis])
Series.gt(other[, axis])
Series.le(other[, axis])
Series.ge(other[, axis])
Series.ne(other[, axis])
Series.eq(other[, axis])

Function application, GroupBy & Window

Series.apply(func[, convert_dtype, args]) Invoke function on values of Series.
Series.map(arg[, na_action]) Map values of Series using input correspondence (which can be
Series.groupby([by, axis, level, as_index, ...]) Group series using mapper (dict or key function, apply given function to group, return result as series) or by a series of columns.
Series.rolling(window[, min_periods, freq, ...]) Provides rolling window calculcations.
Series.expanding([min_periods, freq, ...]) Provides expanding transformations.
Series.ewm([com, span, halflife, alpha, ...]) Provides exponential weighted functions

Computations / Descriptive Stats

Series.abs() Return an object with absolute value taken–only applicable to objects that are all numeric.
Series.all([axis, bool_only, skipna, level]) Return whether all elements are True over requested axis
Series.any([axis, bool_only, skipna, level]) Return whether any element is True over requested axis
Series.autocorr([lag]) Lag-N autocorrelation
Series.between(left, right[, inclusive]) Return boolean Series equivalent to left <= series <= right.
Series.clip([lower, upper, axis]) Trim values at input threshold(s).
Series.clip_lower(threshold[, axis]) Return copy of the input with values below given value(s) truncated.
Series.clip_upper(threshold[, axis]) Return copy of input with values above given value(s) truncated.
Series.corr(other[, method, min_periods]) Compute correlation with other Series, excluding missing values
Series.count([level]) Return number of non-NA/null observations in the Series
Series.cov(other[, min_periods]) Compute covariance with Series, excluding missing values
Series.cummax([axis, skipna]) Return cumulative max over requested axis.
Series.cummin([axis, skipna]) Return cumulative minimum over requested axis.
Series.cumprod([axis, skipna]) Return cumulative product over requested axis.
Series.cumsum([axis, skipna]) Return cumulative sum over requested axis.
Series.describe([percentiles, include, exclude]) Generate various summary statistics, excluding NaN values.
Series.diff([periods]) 1st discrete difference of object
Series.factorize([sort, na_sentinel]) Encode the object as an enumerated type or categorical variable
Series.kurt([axis, skipna, level, numeric_only]) Return unbiased kurtosis over requested axis using Fisher’s definition of kurtosis (kurtosis of normal == 0.0).
Series.mad([axis, skipna, level]) Return the mean absolute deviation of the values for the requested axis
Series.max([axis, skipna, level, numeric_only]) This method returns the maximum of the values in the object.
Series.mean([axis, skipna, level, numeric_only]) Return the mean of the values for the requested axis
Series.median([axis, skipna, level, ...]) Return the median of the values for the requested axis
Series.min([axis, skipna, level, numeric_only]) This method returns the minimum of the values in the object.
Series.mode() Returns the mode(s) of the dataset.
Series.nlargest(*args, **kwargs) Return the largest n elements.
Series.nsmallest(*args, **kwargs) Return the smallest n elements.
Series.pct_change([periods, fill_method, ...]) Percent change over given number of periods.
Series.prod([axis, skipna, level, numeric_only]) Return the product of the values for the requested axis
Series.quantile([q, interpolation]) Return value at the given quantile, a la numpy.percentile.
Series.rank([axis, method, numeric_only, ...]) Compute numerical data ranks (1 through n) along axis.
Series.sem([axis, skipna, level, ddof, ...]) Return unbiased standard error of the mean over requested axis.
Series.skew([axis, skipna, level, numeric_only]) Return unbiased skew over requested axis
Series.std([axis, skipna, level, ddof, ...]) Return sample standard deviation over requested axis.
Series.sum([axis, skipna, level, numeric_only]) Return the sum of the values for the requested axis
Series.var([axis, skipna, level, ddof, ...]) Return unbiased variance over requested axis.
Series.unique() Return array of unique values in the object.
Series.nunique([dropna]) Return number of unique elements in the object.
Series.is_unique Return boolean if values in the object are unique
Series.is_monotonic Return boolean if values in the object are
Series.is_monotonic_increasing Return boolean if values in the object are
Series.is_monotonic_decreasing Return boolean if values in the object are
Series.value_counts([normalize, sort, ...]) Returns object containing counts of unique values.

Reindexing / Selection / Label manipulation

Series.align(other[, join, axis, level, ...]) Align two object on their axes with the
Series.drop(labels[, axis, level, inplace, ...]) Return new object with labels in requested axis removed.
Series.drop_duplicates(*args, **kwargs) Return Series with duplicate values removed
Series.duplicated(*args, **kwargs) Return boolean Series denoting duplicate values
Series.equals(other) Determines if two NDFrame objects contain the same elements.
Series.first(offset) Convenience method for subsetting initial periods of time series data based on a date offset.
Series.head([n]) Returns first n rows
Series.idxmax([axis, skipna]) Index of first occurrence of maximum of values.
Series.idxmin([axis, skipna]) Index of first occurrence of minimum of values.
Series.isin(values) Return a boolean Series showing whether each element in the Series is exactly contained in the passed sequence of values.
Series.last(offset) Convenience method for subsetting final periods of time series data based on a date offset.
Series.reindex([index]) Conform Series to new index with optional filling logic, placing NA/NaN in locations having no value in the previous index.
Series.reindex_like(other[, method, copy, ...]) Return an object with matching indices to myself.
Series.rename([index]) Alter axes input function or functions.
Series.rename_axis(mapper[, axis, copy, inplace]) Alter index and / or columns using input function or functions.
Series.reset_index([level, drop, name, inplace]) Analogous to the pandas.DataFrame.reset_index() function, see docstring there.
Series.sample([n, frac, replace, weights, ...]) Returns a random sample of items from an axis of object.
Series.select(crit[, axis]) Return data corresponding to axis labels matching criteria
Series.take(indices[, axis, convert, is_copy]) return Series corresponding to requested indices
Series.tail([n]) Returns last n rows
Series.truncate([before, after, axis, copy]) Truncates a sorted NDFrame before and/or after some particular index value.
Series.where(cond[, other, inplace, axis, ...]) Return an object of same shape as self and whose corresponding entries are from self where cond is True and otherwise are from other.
Series.mask(cond[, other, inplace, axis, ...]) Return an object of same shape as self and whose corresponding entries are from self where cond is False and otherwise are from other.

Missing data handling

Series.dropna([axis, inplace]) Return Series without null values
Series.fillna([value, method, axis, ...]) Fill NA/NaN values using the specified method
Series.interpolate([method, axis, limit, ...]) Interpolate values according to different methods.

Reshaping, sorting

Series.argsort([axis, kind, order]) Overrides ndarray.argsort.
Series.reorder_levels(order) Rearrange index levels using input order.
Series.sort_values([axis, ascending, ...]) Sort by the values along either axis
Series.sort_index([axis, level, ascending, ...]) Sort object by labels (along an axis)
Series.sortlevel([level, ascending, ...]) Sort Series with MultiIndex by chosen level.
Series.swaplevel([i, j, copy]) Swap levels i and j in a MultiIndex
Series.unstack([level, fill_value]) Unstack, a.k.a.
Series.searchsorted(v[, side, sorter]) Find indices where elements should be inserted to maintain order.

Combining / joining / merging

Series.append(to_append[, ignore_index, ...]) Concatenate two or more Series.
Series.replace([to_replace, value, inplace, ...]) Replace values given in ‘to_replace’ with ‘value’.
Series.update(other) Modify Series in place using non-NA values from passed Series.

Datetimelike Properties

Series.dt can be used to access the values of the series as datetimelike and return several properties. These can be accessed like Series.dt.<property>.

Datetime Properties

Series.dt.date Returns numpy array of datetime.date.
Series.dt.time Returns numpy array of datetime.time.
Series.dt.year The year of the datetime
Series.dt.month The month as January=1, December=12
Series.dt.day The days of the datetime
Series.dt.hour The hours of the datetime
Series.dt.minute The minutes of the datetime
Series.dt.second The seconds of the datetime
Series.dt.microsecond The microseconds of the datetime
Series.dt.nanosecond The nanoseconds of the datetime
Series.dt.week The week ordinal of the year
Series.dt.weekofyear The week ordinal of the year
Series.dt.dayofweek The day of the week with Monday=0, Sunday=6
Series.dt.weekday The day of the week with Monday=0, Sunday=6
Series.dt.weekday_name The name of day in a week (ex: Friday)
Series.dt.dayofyear The ordinal day of the year
Series.dt.quarter The quarter of the date
Series.dt.is_month_start Logical indicating if first day of month (defined by frequency)
Series.dt.is_month_end Logical indicating if last day of month (defined by frequency)
Series.dt.is_quarter_start Logical indicating if first day of quarter (defined by frequency)
Series.dt.is_quarter_end Logical indicating if last day of quarter (defined by frequency)
Series.dt.is_year_start Logical indicating if first day of year (defined by frequency)
Series.dt.is_year_end Logical indicating if last day of year (defined by frequency)
Series.dt.is_leap_year Logical indicating if the date belongs to a leap year
Series.dt.daysinmonth The number of days in the month
Series.dt.days_in_month The number of days in the month
Series.dt.tz
Series.dt.freq get/set the frequncy of the Index

Datetime Methods

Series.dt.to_period(*args, **kwargs) Cast to PeriodIndex at a particular frequency
Series.dt.to_pydatetime()
Series.dt.tz_localize(*args, **kwargs) Localize tz-naive DatetimeIndex to given time zone (using
Series.dt.tz_convert(*args, **kwargs) Convert tz-aware DatetimeIndex from one time zone to another (using
Series.dt.normalize(*args, **kwargs) Return DatetimeIndex with times to midnight.
Series.dt.strftime(*args, **kwargs) Return an array of formatted strings specified by date_format, which supports the same string format as the python standard library.
Series.dt.round(*args, **kwargs) round the index to the specified freq
Series.dt.floor(*args, **kwargs) floor the index to the specified freq
Series.dt.ceil(*args, **kwargs) floor the index to the specified freq

Timedelta Properties

Series.dt.days Number of days for each element.
Series.dt.seconds Number of seconds (>= 0 and less than 1 day) for each element.
Series.dt.microseconds Number of microseconds (>= 0 and less than 1 second) for each element.
Series.dt.nanoseconds Number of nanoseconds (>= 0 and less than 1 microsecond) for each element.
Series.dt.components Return a dataframe of the components (days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) of the Timedeltas.

Timedelta Methods

Series.dt.to_pytimedelta()
Series.dt.total_seconds(*args, **kwargs) Total duration of each element expressed in seconds.

String handling

Series.str can be used to access the values of the series as strings and apply several methods to it. These can be accessed like Series.str.<function/property>.

Series.str.capitalize() Convert strings in the Series/Index to be capitalized.
Series.str.cat([others, sep, na_rep]) Concatenate strings in the Series/Index with given separator.
Series.str.center(width[, fillchar]) Filling left and right side of strings in the Series/Index with an additional character.
Series.str.contains(pat[, case, flags, na, ...]) Return boolean Series/array whether given pattern/regex is contained in each string in the Series/Index.
Series.str.count(pat[, flags]) Count occurrences of pattern in each string of the Series/Index.
Series.str.decode(encoding[, errors]) Decode character string in the Series/Index using indicated encoding.
Series.str.encode(encoding[, errors]) Encode character string in the Series/Index using indicated encoding.
Series.str.endswith(pat[, na]) Return boolean Series indicating whether each string in the Series/Index ends with passed pattern.
Series.str.extract(pat[, flags, expand]) For each subject string in the Series, extract groups from the first match of regular expression pat.
Series.str.extractall(pat[, flags]) For each subject string in the Series, extract groups from all matches of regular expression pat.
Series.str.find(sub[, start, end]) Return lowest indexes in each strings in the Series/Index where the substring is fully contained between [start:end].
Series.str.findall(pat[, flags]) Find all occurrences of pattern or regular expression in the Series/Index.
Series.str.get(i) Extract element from lists, tuples, or strings in each element in the Series/Index.
Series.str.index(sub[, start, end]) Return lowest indexes in each strings where the substring is fully contained between [start:end].
Series.str.join(sep) Join lists contained as elements in the Series/Index with passed delimiter.
Series.str.len() Compute length of each string in the Series/Index.
Series.str.ljust(width[, fillchar]) Filling right side of strings in the Series/Index with an additional character.
Series.str.lower() Convert strings in the Series/Index to lowercase.
Series.str.lstrip([to_strip]) Strip whitespace (including newlines) from each string in the Series/Index from left side.
Series.str.match(pat[, case, flags, na, ...]) Deprecated: Find groups in each string in the Series/Index using passed regular expression.
Series.str.normalize(form) Return the Unicode normal form for the strings in the Series/Index.
Series.str.pad(width[, side, fillchar]) Pad strings in the Series/Index with an additional character to specified side.
Series.str.partition([pat, expand]) Split the string at the first occurrence of sep, and return 3 elements containing the part before the separator, the separator itself, and the part after the separator.
Series.str.repeat(repeats) Duplicate each string in the Series/Index by indicated number of times.
Series.str.replace(pat, repl[, n, case, flags]) Replace occurrences of pattern/regex in the Series/Index with some other string.
Series.str.rfind(sub[, start, end]) Return highest indexes in each strings in the Series/Index where the substring is fully contained between [start:end].
Series.str.rindex(sub[, start, end]) Return highest indexes in each strings where the substring is fully contained between [start:end].
Series.str.rjust(width[, fillchar]) Filling left side of strings in the Series/Index with an additional character.
Series.str.rpartition([pat, expand]) Split the string at the last occurrence of sep, and return 3 elements containing the part before the separator, the separator itself, and the part after the separator.
Series.str.rstrip([to_strip]) Strip whitespace (including newlines) from each string in the Series/Index from right side.
Series.str.slice([start, stop, step]) Slice substrings from each element in the Series/Index
Series.str.slice_replace([start, stop, repl]) Replace a slice of each string in the Series/Index with another string.
Series.str.split([pat, n, expand]) Split each string (a la re.split) in the Series/Index by given pattern, propagating NA values.
Series.str.rsplit([pat, n, expand]) Split each string in the Series/Index by the given delimiter string, starting at the end of the string and working to the front.
Series.str.startswith(pat[, na]) Return boolean Series/array indicating whether each string in the Series/Index starts with passed pattern.
Series.str.strip([to_strip]) Strip whitespace (including newlines) from each string in the Series/Index from left and right sides.
Series.str.swapcase() Convert strings in the Series/Index to be swapcased.
Series.str.title() Convert strings in the Series/Index to titlecase.
Series.str.translate(table[, deletechars]) Map all characters in the string through the given mapping table.
Series.str.upper() Convert strings in the Series/Index to uppercase.
Series.str.wrap(width, **kwargs) Wrap long strings in the Series/Index to be formatted in paragraphs with length less than a given width.
Series.str.zfill(width) Filling left side of strings in the Series/Index with 0.
Series.str.isalnum() Check whether all characters in each string in the Series/Index are alphanumeric.
Series.str.isalpha() Check whether all characters in each string in the Series/Index are alphabetic.
Series.str.isdigit() Check whether all characters in each string in the Series/Index are digits.
Series.str.isspace() Check whether all characters in each string in the Series/Index are whitespace.
Series.str.islower() Check whether all characters in each string in the Series/Index are lowercase.
Series.str.isupper() Check whether all characters in each string in the Series/Index are uppercase.
Series.str.istitle() Check whether all characters in each string in the Series/Index are titlecase.
Series.str.isnumeric() Check whether all characters in each string in the Series/Index are numeric.
Series.str.isdecimal() Check whether all characters in each string in the Series/Index are decimal.
Series.str.get_dummies([sep]) Split each string in the Series by sep and return a frame of dummy/indicator variables.

Categorical

If the Series is of dtype category, Series.cat can be used to change the the categorical data. This accessor is similar to the Series.dt or Series.str and has the following usable methods and properties:

Series.cat.categories The categories of this categorical.
Series.cat.ordered Gets the ordered attribute
Series.cat.codes
Series.cat.rename_categories(*args, **kwargs) Renames categories.
Series.cat.reorder_categories(*args, **kwargs) Reorders categories as specified in new_categories.
Series.cat.add_categories(*args, **kwargs) Add new categories.
Series.cat.remove_categories(*args, **kwargs) Removes the specified categories.
Series.cat.remove_unused_categories(*args, ...) Removes categories which are not used.
Series.cat.set_categories(*args, **kwargs) Sets the categories to the specified new_categories.
Series.cat.as_ordered(*args, **kwargs) Sets the Categorical to be ordered
Series.cat.as_unordered(*args, **kwargs) Sets the Categorical to be unordered

To create a Series of dtype category, use cat = s.astype("category").

The following two Categorical constructors are considered API but should only be used when adding ordering information or special categories is need at creation time of the categorical data:

Categorical(values[, categories, ordered, ...]) Represents a categorical variable in classic R / S-plus fashion
Categorical.from_codes(codes, categories[, ...]) Make a Categorical type from codes and categories arrays.

np.asarray(categorical) works by implementing the array interface. Be aware, that this converts the Categorical back to a numpy array, so levels and order information is not preserved!

Categorical.__array__([dtype]) The numpy array interface.

Plotting

Series.plot is both a callable method and a namespace attribute for specific plotting methods of the form Series.plot.<kind>.

Series.plot([kind, ax, figsize, ....]) Series plotting accessor and method
Series.plot.area(**kwds) Area plot
Series.plot.bar(**kwds) Vertical bar plot
Series.plot.barh(**kwds) Horizontal bar plot
Series.plot.box(**kwds) Boxplot
Series.plot.density(**kwds) Kernel Density Estimate plot
Series.plot.hist([bins]) Histogram
Series.plot.kde(**kwds) Kernel Density Estimate plot
Series.plot.line(**kwds) Line plot
Series.plot.pie(**kwds) Pie chart
Series.hist([by, ax, grid, xlabelsize, ...]) Draw histogram of the input series using matplotlib

Serialization / IO / Conversion

Series.from_csv(path[, sep, parse_dates, ...]) Read CSV file (DISCOURAGED, please use pandas.read_csv() instead).
Series.to_pickle(path) Pickle (serialize) object to input file path.
Series.to_csv(path[, index, sep, na_rep, ...]) Write Series to a comma-separated values (csv) file
Series.to_dict() Convert Series to {label -> value} dict
Series.to_frame([name]) Convert Series to DataFrame
Series.to_xarray() Return an xarray object from the pandas object.
Series.to_hdf(path_or_buf, key, **kwargs) Activate the HDFStore.
Series.to_sql(name, con[, flavor, schema, ...]) Write records stored in a DataFrame to a SQL database.
Series.to_msgpack([path_or_buf, encoding]) msgpack (serialize) object to input file path
Series.to_json([path_or_buf, orient, ...]) Convert the object to a JSON string.
Series.to_sparse([kind, fill_value]) Convert Series to SparseSeries
Series.to_dense() Return dense representation of NDFrame (as opposed to sparse)
Series.to_string([buf, na_rep, ...]) Render a string representation of the Series
Series.to_clipboard([excel, sep]) Attempt to write text representation of object to the system clipboard This can be pasted into Excel, for example.

Sparse methods

SparseSeries.to_coo([row_levels, ...]) Create a scipy.sparse.coo_matrix from a SparseSeries with MultiIndex.
SparseSeries.from_coo(A[, dense_index]) Create a SparseSeries from a scipy.sparse.coo_matrix.