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
- dataarray-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.
- indexarray-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.
- dtypestr, 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.
- namestr, optional
The name to give to the Series.
- copybool, default False
Copy input data.
Attributes
Return the transpose, which is by definition self.
The ExtensionArray of the data backing this Series or Index.
Access a single value for a row/column label pair.
Dictionary of global attributes on this object.
Return a list of the row axis labels.
Return the dtype object of the underlying data.
Return the dtype object of the underlying data.
Return if I have any nans; enables various perf speedups.
Access a single value for a row/column pair by integer position.
Purely integer-location based indexing for selection by position.
The index (axis labels) of the Series.
Return boolean if values in the object are monotonic_increasing.
Return boolean if values in the object are monotonic_decreasing.
Alias for is_monotonic.
Return boolean if values in the object are unique.
Access a group of rows and columns by label(s) or a boolean array.
Return the name of the Series.
Return the number of bytes in the underlying data.
Number of dimensions of the underlying data, by definition 1.
Return a tuple of the shape of the underlying data.
Return the number of elements in the underlying data.
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.
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])Return int position of the largest value in the Series.
argmin
(self[, axis, skipna])Return int position of the smallest value in the Series.
argsort
(self[, axis, kind, order])Return the integer indices that would sort the Series values.
asfreq
(self, freq[, method, fill_value])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., 9:30AM).
autocorr
(self[, lag])Compute the lag-N autocorrelation.
backfill
(self[, axis, limit, downcast])Synonym for
DataFrame.fillna()
withmethod='bfill'
.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, limit, downcast])Synonym for
DataFrame.fillna()
withmethod='bfill'
.bool
(self)Return the bool of a single element Series or DataFrame.
alias of
pandas.core.arrays.categorical.CategoricalAccessor
clip
(self[, lower, upper, axis])Trim values at input threshold(s).
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.
compare
(self, other, align_axis, int] = 1, …)Compare to another Series and show the differences.
convert_dtypes
(self, infer_objects, …)Convert columns to best possible dtypes using dtypes supporting
pd.NA
.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, …])Generate descriptive statistics.
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, how])Return a new Series with missing values removed.
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 (EW) functions.
expanding
(self[, min_periods, center, axis])Provide expanding transformations.
explode
(self, ignore_index)Transform each element of a list-like to a row.
factorize
(self, sort, na_sentinel, …)Encode the object as an enumerated type or categorical variable.
ffill
(self[, axis, limit, downcast])Synonym for
DataFrame.fillna()
withmethod='ffill'
.fillna
(self[, value, method, axis, inplace, …])Fill NA/NaN values using the specified method.
filter
(self[, items, axis])Subset the dataframe rows or columns according to the specified index labels.
first
(self, offset)Select 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).
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).
groupby
(self[, by, axis, level])Group 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])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, int] = 0, …)Please note that only
method='linear'
is supported for DataFrame/Series with a MultiIndex.isin
(self, values)Whether elements in Series are contained in values.
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.
kurtosis
(self[, axis, skipna, level, …])Return unbiased kurtosis over requested axis.
last
(self, offset)Select 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.
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.
pad
(self[, axis, limit, downcast])Synonym for
DataFrame.fillna()
withmethod='ffill'
.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).
alias of
pandas.plotting._core.PlotAccessor
pop
(self, item, NoneType])Return item and drops from series.
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.
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])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.
reindex_like
(self, other, method, …[, …])Return an object with matching indices as other object.
rename
(self[, index, axis, copy, inplace, …])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[, axis, loffset, on, level])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, int] = 0, inplace)Assign desired index to given axis.
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.
slice_shift
(self, periods[, axis])Equivalent to shift without copying data.
sort_index
(self[, axis, level])Sort Series by index labels.
sort_values
(self[, axis, ascending])Sort by the values.
alias of
pandas.core.arrays.sparse.accessor.SparseAccessor
squeeze
(self[, axis])Squeeze 1 dimensional axis objects into scalars.
std
(self[, axis, skipna, level, ddof, …])Return sample standard deviation over requested axis.
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, path_or_buf, pathlib.Path, …)Write object to a comma-separated values (csv) file.
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, mode, …[, …])Write the contained data to an HDF5 file using HDFStore.
to_json
(self, path_or_buf, pathlib.Path, …)Convert the object to a JSON string.
to_latex
(self[, buf, columns, col_space, …])Render object to a LaTeX tabular, longtable, or nested table/tabular.
to_list
(self)Return a list of the values.
to_markdown
(self, buf, NoneType] = None, …)Print Series in Markdown-friendly format.
to_numpy
(self[, dtype, copy, na_value])A NumPy ndarray representing the values in this Series or Index.
to_period
(self[, freq, copy])Convert Series from DatetimeIndex to PeriodIndex.
to_pickle
(self, path, compression, …)Pickle (serialize) object to file.
to_sql
(self, name, con[, schema, …])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.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])Truncate a Series or DataFrame before and after some index value.
tshift
(self, periods[, freq])(DEPRECATED) Shift the time index, using the index’s frequency if available.
tz_convert
(self, tz[, axis, level])Convert tz-aware axis to target time zone.
tz_localize
(self, tz[, axis, level, ambiguous])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, also known as pivot, Series with MultiIndex to produce DataFrame.
update
(self, other)Modify Series in place using values from passed Series.
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])Return cross-section from the Series/DataFrame.