pandas.Series

class pandas.Series(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False)[source]

One-dimensional ndarray with axis labels (including time series).

Labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Statistical methods from ndarray have been overridden to automatically exclude missing data (currently represented as NaN).

Operations between Series (+, -, /, , *) align values based on their associated index values– they need not be the same length. The result index will be the sorted union of the two indexes.

Parameters:
data : array-like, Iterable, dict, or scalar value

Contains data stored in Series.

Changed in version 0.23.0: If data is a dict, argument order is maintained for Python 3.6 and later.

index : array-like or Index (1d)

Values must be hashable and have the same length as data. Non-unique index values are allowed. Will default to RangeIndex (0, 1, 2, …, n) if not provided. If both a dict and index sequence are used, the index will override the keys found in the dict.

dtype : str, numpy.dtype, or ExtensionDtype, optional

Data type for the output Series. If not specified, this will be inferred from data. See the user guide for more usages.

copy : bool, default False

Copy input data.

Attributes

T Return the transpose, which is by
array The ExtensionArray of the data backing this Series or Index.
asobject Return object Series which contains boxed values.
at Access a single value for a row/column label pair.
axes Return a list of the row axis labels.
base (DEPRECATED) Return the base object if the memory of the underlying data is shared.
blocks (DEPRECATED) Internal property, property synonym for as_blocks().
data (DEPRECATED) Return the data pointer of the underlying data.
dtype Return the dtype object of the underlying data.
dtypes Return the dtype object of the underlying data.
flags (DEPRECATED)
ftype (DEPRECATED) Return if the data is sparse|dense.
ftypes (DEPRECATED) Return if the data is sparse|dense.
hasnans Return if I have any nans; enables various perf speedups.
iat Access a single value for a row/column pair by integer position.
iloc Purely integer-location based indexing for selection by position.
imag Return imag value of vector.
index The index (axis labels) of the Series.
is_copy Return the copy.
is_monotonic Return boolean if values in the object are monotonic_increasing.
is_monotonic_decreasing Return boolean if values in the object are monotonic_decreasing.
is_monotonic_increasing Return boolean if values in the object are monotonic_increasing.
is_unique Return boolean if values in the object are unique.
itemsize (DEPRECATED) Return the size of the dtype of the item of the underlying data.
ix A primarily label-location based indexer, with integer position fallback.
loc Access a group of rows and columns by label(s) or a boolean array.
name Return name of the Series.
nbytes Return the number of bytes in the underlying data.
ndim Number of dimensions of the underlying data, by definition 1.
real Return the real value of vector.
shape Return a tuple of the shape of the underlying data.
size Return the number of elements in the underlying data.
strides (DEPRECATED) Return the strides of the underlying data.
values Return Series as ndarray or ndarray-like depending on the dtype.
empty  

Methods

abs(self) Return a Series/DataFrame with absolute numeric value of each element.
add(self, other[, level, fill_value, axis]) Return Addition of series and other, element-wise (binary operator add).
add_prefix(self, prefix) Prefix labels with string prefix.
add_suffix(self, suffix) Suffix labels with string suffix.
agg(self, func[, axis]) Aggregate using one or more operations over the specified axis.
aggregate(self, func[, axis]) Aggregate using one or more operations over the specified axis.
align(self, other[, join, axis, level, …]) Align two objects on their axes with the specified join method for each axis Index.
all(self[, axis, bool_only, skipna, level]) Return whether all elements are True, potentially over an axis.
any(self[, axis, bool_only, skipna, level]) Return whether any element is True, potentially over an axis.
append(self, to_append[, ignore_index, …]) Concatenate two or more Series.
apply(self, func[, convert_dtype, args]) Invoke function on values of Series.
argmax(self[, axis, skipna]) (DEPRECATED) Return the row label of the maximum value.
argmin(self[, axis, skipna]) (DEPRECATED) Return the row label of the minimum value.
argsort(self[, axis, kind, order]) Override ndarray.argsort.
as_blocks(self[, copy]) (DEPRECATED) Convert the frame to a dict of dtype -> Constructor Types that each has a homogeneous dtype.
as_matrix(self[, columns]) (DEPRECATED) Convert the frame to its Numpy-array representation.
asfreq(self, freq[, method, how, normalize, …]) Convert TimeSeries to specified frequency.
asof(self, where[, subset]) Return the last row(s) without any NaNs before where.
astype(self, dtype[, copy, errors]) Cast a pandas object to a specified dtype dtype.
at_time(self, time[, asof, axis]) Select values at particular time of day (e.g.
autocorr(self[, lag]) Compute the lag-N autocorrelation.
between(self, left, right[, inclusive]) Return boolean Series equivalent to left <= series <= right.
between_time(self, start_time, end_time[, …]) Select values between particular times of the day (e.g., 9:00-9:30 AM).
bfill(self[, axis, inplace, limit, downcast]) Synonym for DataFrame.fillna() with method='bfill'.
bool(self) Return the bool of a single element PandasObject.
cat alias of pandas.core.arrays.categorical.CategoricalAccessor
clip(self[, lower, upper, axis, inplace]) Trim values at input threshold(s).
clip_lower(self, threshold[, axis, inplace]) (DEPRECATED) Trim values below a given threshold.
clip_upper(self, threshold[, axis, inplace]) (DEPRECATED) Trim values above a given threshold.
combine(self, other, func[, fill_value]) Combine the Series with a Series or scalar according to func.
combine_first(self, other) Combine Series values, choosing the calling Series’s values first.
compound(self[, axis, skipna, level]) (DEPRECATED) Return the compound percentage of the values for the requested axis.
compress(self, condition, \*args, \*\*kwargs) (DEPRECATED) Return selected slices of an array along given axis as a Series.
copy(self[, deep]) Make a copy of this object’s indices and data.
corr(self, other[, method, min_periods]) Compute correlation with other Series, excluding missing values.
count(self[, level]) Return number of non-NA/null observations in the Series.
cov(self, other[, min_periods]) Compute covariance with Series, excluding missing values.
cummax(self[, axis, skipna]) Return cumulative maximum over a DataFrame or Series axis.
cummin(self[, axis, skipna]) Return cumulative minimum over a DataFrame or Series axis.
cumprod(self[, axis, skipna]) Return cumulative product over a DataFrame or Series axis.
cumsum(self[, axis, skipna]) Return cumulative sum over a DataFrame or Series axis.
describe(self[, percentiles, include, exclude]) Generate descriptive statistics that summarize the central tendency, dispersion and shape of a dataset’s distribution, excluding NaN values.
diff(self[, periods]) First discrete difference of element.
div(self, other[, level, fill_value, axis]) Return Floating division of series and other, element-wise (binary operator truediv).
divide(self, other[, level, fill_value, axis]) Return Floating division of series and other, element-wise (binary operator truediv).
divmod(self, other[, level, fill_value, axis]) Return Integer division and modulo of series and other, element-wise (binary operator divmod).
dot(self, other) Compute the dot product between the Series and the columns of other.
drop(self[, labels, axis, index, columns, …]) Return Series with specified index labels removed.
drop_duplicates(self[, keep, inplace]) Return Series with duplicate values removed.
droplevel(self, level[, axis]) Return DataFrame with requested index / column level(s) removed.
dropna(self[, axis, inplace]) Return a new Series with missing values removed.
dt alias of pandas.core.indexes.accessors.CombinedDatetimelikeProperties
duplicated(self[, keep]) Indicate duplicate Series values.
eq(self, other[, level, fill_value, axis]) Return Equal to of series and other, element-wise (binary operator eq).
equals(self, other) Test whether two objects contain the same elements.
ewm(self[, com, span, halflife, alpha, …]) Provide exponential weighted functions.
expanding(self[, min_periods, center, axis]) Provide expanding transformations.
explode(self) Transform each element of a list-like to a row, replicating the index values.
factorize(self[, sort, na_sentinel]) Encode the object as an enumerated type or categorical variable.
ffill(self[, axis, inplace, limit, downcast]) Synonym for DataFrame.fillna() with method='ffill'.
fillna(self[, value, method, axis, inplace, …]) Fill NA/NaN values using the specified method.
filter(self[, items, like, regex, axis]) Subset rows or columns of dataframe according to labels in the specified index.
first(self, offset) Convenience method for subsetting initial periods of time series data based on a date offset.
first_valid_index(self) Return index for first non-NA/null value.
floordiv(self, other[, level, fill_value, axis]) Return Integer division of series and other, element-wise (binary operator floordiv).
from_array(arr[, index, name, dtype, copy, …]) Construct Series from array.
ge(self, other[, level, fill_value, axis]) Return Greater than or equal to of series and other, element-wise (binary operator ge).
get(self, key[, default]) Get item from object for given key (ex: DataFrame column).
get_dtype_counts(self) (DEPRECATED) Return counts of unique dtypes in this object.
get_ftype_counts(self) (DEPRECATED) Return counts of unique ftypes in this object.
get_value(self, label[, takeable]) (DEPRECATED) Quickly retrieve single value at passed index label.
get_values(self) (DEPRECATED) Same as values (but handles sparseness conversions); is a view.
groupby(self[, by, axis, level, as_index, …]) Group DataFrame or Series using a mapper or by a Series of columns.
gt(self, other[, level, fill_value, axis]) Return Greater than of series and other, element-wise (binary operator gt).
head(self[, n]) Return the first n rows.
hist(self[, by, ax, grid, xlabelsize, xrot, …]) Draw histogram of the input series using matplotlib.
idxmax(self[, axis, skipna]) Return the row label of the maximum value.
idxmin(self[, axis, skipna]) Return the row label of the minimum value.
infer_objects(self) Attempt to infer better dtypes for object columns.
interpolate(self[, method, axis, limit, …]) Interpolate values according to different methods.
isin(self, values) Check whether values are contained in Series.
isna(self) Detect missing values.
isnull(self) Detect missing values.
item(self) Return the first element of the underlying data as a python scalar.
items(self) Lazily iterate over (index, value) tuples.
iteritems(self) Lazily iterate over (index, value) tuples.
keys(self) Return alias for index.
kurt(self[, axis, skipna, level, numeric_only]) Return unbiased kurtosis over requested axis using Fisher’s definition of kurtosis (kurtosis of normal == 0.0).
kurtosis(self[, axis, skipna, level, …]) Return unbiased kurtosis over requested axis using Fisher’s definition of kurtosis (kurtosis of normal == 0.0).
last(self, offset) Convenience method for subsetting final periods of time series data based on a date offset.
last_valid_index(self) Return index for last non-NA/null value.
le(self, other[, level, fill_value, axis]) Return Less than or equal to of series and other, element-wise (binary operator le).
lt(self, other[, level, fill_value, axis]) Return Less than of series and other, element-wise (binary operator lt).
mad(self[, axis, skipna, level]) Return the mean absolute deviation of the values for the requested axis.
map(self, arg[, na_action]) Map values of Series according to input correspondence.
mask(self, cond[, other, inplace, axis, …]) Replace values where the condition is True.
max(self[, axis, skipna, level, numeric_only]) Return the maximum of the values for the requested axis.
mean(self[, axis, skipna, level, numeric_only]) Return the mean of the values for the requested axis.
median(self[, axis, skipna, level, numeric_only]) Return the median of the values for the requested axis.
memory_usage(self[, index, deep]) Return the memory usage of the Series.
min(self[, axis, skipna, level, numeric_only]) Return the minimum of the values for the requested axis.
mod(self, other[, level, fill_value, axis]) Return Modulo of series and other, element-wise (binary operator mod).
mode(self[, dropna]) Return the mode(s) of the dataset.
mul(self, other[, level, fill_value, axis]) Return Multiplication of series and other, element-wise (binary operator mul).
multiply(self, other[, level, fill_value, axis]) Return Multiplication of series and other, element-wise (binary operator mul).
ne(self, other[, level, fill_value, axis]) Return Not equal to of series and other, element-wise (binary operator ne).
nlargest(self[, n, keep]) Return the largest n elements.
nonzero(self) (DEPRECATED) Return the integer indices of the elements that are non-zero.
notna(self) Detect existing (non-missing) values.
notnull(self) Detect existing (non-missing) values.
nsmallest(self[, n, keep]) Return the smallest n elements.
nunique(self[, dropna]) Return number of unique elements in the object.
pct_change(self[, periods, fill_method, …]) Percentage change between the current and a prior element.
pipe(self, func, \*args, \*\*kwargs) Apply func(self, *args, **kwargs).
plot alias of pandas.plotting._core.PlotAccessor
pop(self, item) Return item and drop from frame.
pow(self, other[, level, fill_value, axis]) Return Exponential power of series and other, element-wise (binary operator pow).
prod(self[, axis, skipna, level, …]) Return the product of the values for the requested axis.
product(self[, axis, skipna, level, …]) Return the product of the values for the requested axis.
ptp(self[, axis, skipna, level, numeric_only]) (DEPRECATED) Return the difference between the maximum value and the
put(self, \*args, \*\*kwargs) (DEPRECATED) Apply the put method to its values attribute if it has one.
quantile(self[, q, interpolation]) Return value at the given quantile.
radd(self, other[, level, fill_value, axis]) Return Addition of series and other, element-wise (binary operator radd).
rank(self[, axis, method, numeric_only, …]) Compute numerical data ranks (1 through n) along axis.
ravel(self[, order]) Return the flattened underlying data as an ndarray.
rdiv(self, other[, level, fill_value, axis]) Return Floating division of series and other, element-wise (binary operator rtruediv).
rdivmod(self, other[, level, fill_value, axis]) Return Integer division and modulo of series and other, element-wise (binary operator rdivmod).
reindex(self[, index]) Conform Series to new index with optional filling logic, placing NA/NaN in locations having no value in the previous index.
reindex_like(self, other[, method, copy, …]) Return an object with matching indices as other object.
rename(self[, index]) Alter Series index labels or name.
rename_axis(self[, mapper, index, columns, …]) Set the name of the axis for the index or columns.
reorder_levels(self, order) Rearrange index levels using input order.
repeat(self, repeats[, axis]) Repeat elements of a Series.
replace(self[, to_replace, value, inplace, …]) Replace values given in to_replace with value.
resample(self, rule[, how, axis, …]) Resample time-series data.
reset_index(self[, level, drop, name, inplace]) Generate a new DataFrame or Series with the index reset.
rfloordiv(self, other[, level, fill_value, axis]) Return Integer division of series and other, element-wise (binary operator rfloordiv).
rmod(self, other[, level, fill_value, axis]) Return Modulo of series and other, element-wise (binary operator rmod).
rmul(self, other[, level, fill_value, axis]) Return Multiplication of series and other, element-wise (binary operator rmul).
rolling(self, window[, min_periods, center, …]) Provide rolling window calculations.
round(self[, decimals]) Round each value in a Series to the given number of decimals.
rpow(self, other[, level, fill_value, axis]) Return Exponential power of series and other, element-wise (binary operator rpow).
rsub(self, other[, level, fill_value, axis]) Return Subtraction of series and other, element-wise (binary operator rsub).
rtruediv(self, other[, level, fill_value, axis]) Return Floating division of series and other, element-wise (binary operator rtruediv).
sample(self[, n, frac, replace, weights, …]) Return a random sample of items from an axis of object.
searchsorted(self, value[, side, sorter]) Find indices where elements should be inserted to maintain order.
sem(self[, axis, skipna, level, ddof, …]) Return unbiased standard error of the mean over requested axis.
set_axis(self, labels[, axis, inplace]) Assign desired index to given axis.
set_value(self, label, value[, takeable]) (DEPRECATED) Quickly set single value at passed label.
shift(self[, periods, freq, axis, fill_value]) Shift index by desired number of periods with an optional time freq.
skew(self[, axis, skipna, level, numeric_only]) Return unbiased skew over requested axis Normalized by N-1.
slice_shift(self[, periods, axis]) Equivalent to shift without copying data.
sort_index(self[, axis, level, ascending, …]) Sort Series by index labels.
sort_values(self[, axis, ascending, …]) Sort by the values.
sparse alias of pandas.core.arrays.sparse.SparseAccessor
squeeze(self[, axis]) Squeeze 1 dimensional axis objects into scalars.
std(self[, axis, skipna, level, ddof, …]) Return sample standard deviation over requested axis.
str alias of pandas.core.strings.StringMethods
sub(self, other[, level, fill_value, axis]) Return Subtraction of series and other, element-wise (binary operator sub).
subtract(self, other[, level, fill_value, axis]) Return Subtraction of series and other, element-wise (binary operator sub).
sum(self[, axis, skipna, level, …]) Return the sum of the values for the requested axis.
swapaxes(self, axis1, axis2[, copy]) Interchange axes and swap values axes appropriately.
swaplevel(self[, i, j, copy]) Swap levels i and j in a MultiIndex.
tail(self[, n]) Return the last n rows.
take(self, indices[, axis, is_copy]) Return the elements in the given positional indices along an axis.
to_clipboard(self[, excel, sep]) Copy object to the system clipboard.
to_csv(self, \*args, \*\*kwargs) Write object to a comma-separated values (csv) file.
to_dense(self) (DEPRECATED) Return dense representation of Series/DataFrame (as opposed to sparse).
to_dict(self[, into]) Convert Series to {label -> value} dict or dict-like object.
to_excel(self, excel_writer[, sheet_name, …]) Write object to an Excel sheet.
to_frame(self[, name]) Convert Series to DataFrame.
to_hdf(self, path_or_buf, key, \*\*kwargs) Write the contained data to an HDF5 file using HDFStore.
to_json(self[, path_or_buf, orient, …]) Convert the object to a JSON string.
to_latex(self[, buf, columns, col_space, …]) Render an object to a LaTeX tabular environment table.
to_list(self) Return a list of the values.
to_msgpack(self[, path_or_buf, encoding]) (DEPRECATED) Serialize object to input file path using msgpack format.
to_numpy(self[, dtype, copy]) A NumPy ndarray representing the values in this Series or Index.
to_period(self[, freq, copy]) Convert Series from DatetimeIndex to PeriodIndex with desired frequency (inferred from index if not passed).
to_pickle(self, path[, compression, protocol]) Pickle (serialize) object to file.
to_sparse(self[, kind, fill_value]) (DEPRECATED) Convert Series to SparseSeries.
to_sql(self, name, con[, schema, if_exists, …]) Write records stored in a DataFrame to a SQL database.
to_string(self[, buf, na_rep, float_format, …]) Render a string representation of the Series.
to_timestamp(self[, freq, how, copy]) Cast to DatetimeIndex of Timestamps, at beginning of period.
to_xarray(self) Return an xarray object from the pandas object.
tolist(self) Return a list of the values.
transform(self, func[, axis]) Call func on self producing a Series with transformed values and that has the same axis length as self.
transpose(self, \*args, \*\*kwargs) Return the transpose, which is by definition self.
truediv(self, other[, level, fill_value, axis]) Return Floating division of series and other, element-wise (binary operator truediv).
truncate(self[, before, after, axis, copy]) Truncate a Series or DataFrame before and after some index value.
tshift(self[, periods, freq, axis]) Shift the time index, using the index’s frequency if available.
tz_convert(self, tz[, axis, level, copy]) Convert tz-aware axis to target time zone.
tz_localize(self, tz[, axis, level, copy, …]) Localize tz-naive index of a Series or DataFrame to target time zone.
unique(self) Return unique values of Series object.
unstack(self[, level, fill_value]) Unstack, a.k.a.
update(self, other) Modify Series in place using non-NA values from passed Series.
valid(self[, inplace]) (DEPRECATED) Return Series without null values.
value_counts(self[, normalize, sort, …]) Return a Series containing counts of unique values.
var(self[, axis, skipna, level, ddof, …]) Return unbiased variance over requested axis.
view(self[, dtype]) Create a new view of the Series.
where(self, cond[, other, inplace, axis, …]) Replace values where the condition is False.
xs(self, key[, axis, level, drop_level]) Return cross-section from the Series/DataFrame.
Scroll To Top