Series#

Constructor#

Series([data, index, dtype, name, copy, ...])

Attributes#

Axes

Series.index

The index (axis labels) of the Series.

Series.dtype

Return the dtype object of the underlying data.

Series.shape

Series.T

Return the transpose, which is by definition self.

Series.ndim

Return an int representing the number of axes / array dimensions.

Series.name

Conversion#

Series.astype(dtype[, copy, errors])

Cast a pandas object to a specified dtype dtype.

Series.copy([deep])

Make a copy of this object's indices and data.

Binary operator functions#

Series.add(other[, level, fill_value, axis])

Return Addition of series and other, element-wise (binary operator add).

Series.sub(other[, level, fill_value, axis])

Return Subtraction of series and other, element-wise (binary operator subtract).

Series.mul(other[, level, fill_value, axis])

Return Multiplication of series and other, element-wise (binary operator mul).

Series.div(other[, level, fill_value, axis])

Return Floating division of series and other, element-wise (binary operator truediv).

Series.truediv(other[, level, fill_value, axis])

Return Floating division of series and other, element-wise (binary operator truediv).

Series.floordiv(other[, level, fill_value, axis])

Return Integer division of series and other, element-wise (binary operator floordiv).

Series.mod(other[, level, fill_value, axis])

Return Modulo of series and other, element-wise (binary operator mod).

Series.pow(other[, level, fill_value, axis])

Return Exponential power of series and other, element-wise (binary operator pow).

Series.radd(other[, level, fill_value, axis])

Return Addition of series and other, element-wise (binary operator radd).

Series.rsub(other[, level, fill_value, axis])

Return Subtraction of series and other, element-wise (binary operator rsubtract).

Series.rmul(other[, level, fill_value, axis])

Return Multiplication of series and other, element-wise (binary operator rmul).

Series.rdiv(other[, level, fill_value, axis])

Return Floating division of series and other, element-wise (binary operator rtruediv).

Series.rtruediv(other[, level, fill_value, axis])

Return Floating division of series and other, element-wise (binary operator rtruediv).

Series.rfloordiv(other[, level, fill_value, ...])

Return Integer division of series and other, element-wise (binary operator rfloordiv).

Series.rmod(other[, level, fill_value, axis])

Return Modulo of series and other, element-wise (binary operator rmod).

Series.rpow(other[, level, fill_value, axis])

Return Exponential power of series and other, element-wise (binary operator rpow).

Series.lt(other[, level, axis])

Return Less than of series and other, element-wise (binary operator lt).

Series.gt(other[, level, axis])

Return Greater than of series and other, element-wise (binary operator gt).

Series.le(other[, level, axis])

Return Less than or equal to of series and other, element-wise (binary operator le).

Series.ge(other[, level, axis])

Return Greater than or equal to of series and other, element-wise (binary operator ge).

Series.ne(other[, level, axis])

Return Not equal to of series and other, element-wise (binary operator ne).

Series.eq(other[, level, axis])

Return Equal to of series and other, element-wise (binary operator eq).

Function application, groupby & window#

Series.agg([func, axis])

Series.aggregate([func, axis])

Series.groupby([by, level, as_index, sort, ...])

Series.map(arg[, na_action, dtype, ...])

Map values of Series according to input correspondence.

Series.transform(func[, convert_dtype, ...])

Call func on self producing a Series with transformed values.

Computations / descriptive stats#

Series.abs()

Series.all([axis, bool_only, skipna, level, ...])

Series.any([axis, bool_only, skipna, level, ...])

Series.count([level])

Series.max([axis, skipna, level, method])

Series.mean([axis, skipna, level, method])

Series.min([axis, skipna, level, method])

Series.prod([axis, skipna, level, ...])

Series.product([axis, skipna, level, ...])

Series.round([decimals])

Round each value in a Series to the given number of decimals.

Series.sem([axis, skipna, level, ddof, method])

Series.std([axis, skipna, level, ddof, method])

Series.sum([axis, skipna, level, min_count, ...])

Series.var([axis, skipna, level, ddof, method])

Series.nunique([dropna])

Return number of unique elements in the object.

Series.value_counts([normalize, sort, ...])

Return a Series containing counts of unique values.

Reindexing / selection / label manipulation#

Series.add_prefix(prefix)

Prefix labels with string prefix.

Series.add_suffix(suffix)

Suffix labels with string suffix.

Series.drop([labels, axis, index, columns, ...])

Return Series with specified index labels removed.

Series.drop_duplicates([keep, inplace, ...])

Return Series with duplicate values removed.

Series.head([n])

Return the first n rows.

Series.isin(values)

Whether elements in Series are contained in values.

Series.rename([index, axis, copy, inplace, ...])

Alter Series index labels or name.

Series.reset_index([level, drop, name, inplace])

Generate a new DataFrame or Series with the index reset.

Series.sample([n, frac, replace, weights, ...])

Return a random sample of items from an axis of object.

Series.set_axis(labels[, axis, inplace])

Assign desired index to given axis.

Missing data handling#

Series.isna()

Detect missing values.

Series.notna()

Detect existing (non-missing) values.

Series.dropna([axis, inplace, how])

Return a new Series with missing values removed.

Series.fillna([value, method, axis, ...])

Fill NA/NaN values using the specified method.

Reshaping, sorting#

Series.sort_values([axis, ascending, ...])

Sort by the values.

Series.sort_index([axis, level, ascending, ...])

Sort object by labels (along an axis).

Accessors#

Pandas provides dtype-specific methods under various accessors. These are separate namespaces within Series that only apply to specific data types.

Data Type

Accessor

Datetime, Timedelta, Period

dt

String

str

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 python datetime.date objects.

Series.dt.time

Returns numpy array of datetime.time objects.

Series.dt.timetz

Returns numpy array of datetime.time objects with timezones.

Series.dt.year

The year of the datetime.

Series.dt.month

The month as January=1, December=12.

Series.dt.day

The day 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 according to the ISO 8601 standard.

Series.dt.weekofyear

The week ordinal of the year according to the ISO 8601 standard.

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.dayofyear

The ordinal day of the year.

Series.dt.quarter

The quarter of the date.

Series.dt.is_month_start

Indicates whether the date is the first day of the month.

Series.dt.is_month_end

Indicates whether the date is the last day of the month.

Series.dt.is_quarter_start

Indicator for whether the date is the first day of a quarter.

Series.dt.is_quarter_end

Indicator for whether the date is the last day of a quarter.

Series.dt.is_year_start

Indicate whether the date is the first day of a year.

Series.dt.is_year_end

Indicate whether the date is the last day of the year.

Series.dt.is_leap_year

Boolean indicator 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.

Datetime methods#

Series.dt.to_period(*args, **kwargs)

Cast to PeriodArray/Index at a particular frequency.

Series.dt.to_pydatetime()

Return the data as an array of datetime.datetime objects.

Series.dt.tz_localize(*args, **kwargs)

Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index.

Series.dt.tz_convert(*args, **kwargs)

Convert tz-aware Datetime Array/Index from one time zone to another.

Series.dt.normalize(*args, **kwargs)

Convert times to midnight.

Series.dt.strftime(*args, **kwargs)

Convert to Index using specified date_format.

Series.dt.round(*args, **kwargs)

Perform round operation on the data to the specified freq.

Series.dt.floor(*args, **kwargs)

Perform floor operation on the data to the specified freq.

Series.dt.ceil(*args, **kwargs)

Perform ceil operation on the data to the specified freq.

Series.dt.month_name(*args, **kwargs)

Return the month names with specified locale.

Series.dt.day_name(*args, **kwargs)

Return the day names with specified locale.

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.contains(pat[, case, flags, na, ...])

Test if pattern or regex is contained within a string of a Series or Index.

Series.str.count(pat[, flags])

Count occurrences of pattern in each string of the Series/Index.

Series.str.endswith(pat[, na])

Test if the end of each string element matches a pattern.

Series.str.find(sub[, start, end])

Return lowest indexes in each strings in the Series/Index.

Series.str.len()

Compute the length of each element in the Series/Index.

Series.str.ljust(width[, fillchar])

Pad right side of strings in the Series/Index.

Series.str.lower()

Convert strings in the Series/Index to lowercase.

Series.str.lstrip([to_strip])

Remove leading characters.

Series.str.pad(width[, side, fillchar])

Pad strings in the Series/Index up to width.

Series.str.repeat(repeats)

Duplicate each string in the Series or Index.

Series.str.replace(pat, repl[, n, case, ...])

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

Series.str.rfind(sub[, start, end])

Return highest indexes in each strings in the Series/Index.

Series.str.rjust(width[, fillchar])

Pad left side of strings in the Series/Index.

Series.str.rstrip([to_strip])

Remove trailing characters.

Series.str.slice([start, stop, step])

Slice substrings from each element in the Series or Index.

Series.str.startswith(pat[, na])

Test if the start of each string element matches a pattern.

Series.str.strip([to_strip])

Remove leading and trailing characters.

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)

Map all characters in the string through the given mapping table.

Series.str.upper()

Convert strings in the Series/Index to uppercase.

Series.str.zfill(width)

Pad strings in the Series/Index by prepending '0' characters.

Series.str.isalnum()

Check whether all characters in each string are alphanumeric.

Series.str.isalpha()

Check whether all characters in each string are alphabetic.

Series.str.isdigit()

Check whether all characters in each string are digits.

Series.str.isspace()

Check whether all characters in each string are whitespace.

Series.str.islower()

Check whether all characters in each string are lowercase.

Series.str.isupper()

Check whether all characters in each string are uppercase.

Series.str.istitle()

Check whether all characters in each string are titlecase.

Series.str.isnumeric()

Check whether all characters in each string are numeric.

Series.str.isdecimal()

Check whether all characters in each string are decimal.

Plotting#

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

Series.plot

alias of SeriesPlotAccessor

Series.plot.area(*args, **kwargs)

Draw a stacked area plot.

Series.plot.bar(*args, **kwargs)

Vertical bar plot.

Series.plot.barh(*args, **kwargs)

Make a horizontal bar plot.

Series.plot.box(*args, **kwargs)

Make a box plot of the DataFrame columns.

Series.plot.density(*args, **kwargs)

Generate Kernel Density Estimate plot using Gaussian kernels.

Series.plot.hist(*args, **kwargs)

Draw one histogram of the DataFrame's columns.

Series.plot.kde(*args, **kwargs)

Generate Kernel Density Estimate plot using Gaussian kernels.

Series.plot.line(*args, **kwargs)

Plot Series or DataFrame as lines.

Series.plot.pie(*args, **kwargs)

Generate a pie plot.