Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Machine Learning
avec Scikit-Learn
Voir le programme détaillé
Module « pandas »

Classe « Series »

Informations générales

Héritage

    builtins.object
        IndexingMixin
builtins.object
    DirNamesMixin
        PandasObject
            NDFrame
    builtins.object
        OpsMixin
            IndexOpsMixin
                Series

Définition

class Series(IndexOpsMixin, NDFrame):

help(Series)

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. If data is a dict, argument order is
    maintained.
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 data is dict-like
    and index is None, then the keys in the data are used as the index. If the
    index is not None, the resulting Series is reindexed with the index values.
dtype : str, numpy.dtype, or ExtensionDtype, optional
    Data type for the output Series. If not specified, this will be
    inferred from `data`.
    See the :ref:`user guide <basics.dtypes>` for more usages.
name : Hashable, default None
    The name to give to the Series.
copy : bool, default False
    Copy input data. Only affects Series or 1d ndarray input. See examples.

Notes
-----
Please reference the :ref:`User Guide <basics.series>` for more information.

Examples
--------
Constructing Series from a dictionary with an Index specified

>>> d = {'a': 1, 'b': 2, 'c': 3}
>>> ser = pd.Series(data=d, index=['a', 'b', 'c'])
>>> ser
a   1
b   2
c   3
dtype: int64

The keys of the dictionary match with the Index values, hence the Index
values have no effect.

>>> d = {'a': 1, 'b': 2, 'c': 3}
>>> ser = pd.Series(data=d, index=['x', 'y', 'z'])
>>> ser
x   NaN
y   NaN
z   NaN
dtype: float64

Note that the Index is first build with the keys from the dictionary.
After this the Series is reindexed with the given Index values, hence we
get all NaN as a result.

Constructing Series from a list with `copy=False`.

>>> r = [1, 2]
>>> ser = pd.Series(r, copy=False)
>>> ser.iloc[0] = 999
>>> r
[1, 2]
>>> ser
0    999
1      2
dtype: int64

Due to input data type the Series has a `copy` of
the original data even though `copy=False`, so
the data is unchanged.

Constructing Series from a 1d ndarray with `copy=False`.

>>> r = np.array([1, 2])
>>> ser = pd.Series(r, copy=False)
>>> ser.iloc[0] = 999
>>> r
array([999,   2])
>>> ser
0    999
1      2
dtype: int64

Due to input data type the Series has a `view` on
the original data, so
the data is changed as well.

Constructeur(s)

Signature du constructeur Description
__init__(self, data=None, index=None, dtype: 'Dtype | None' = None, name=None, copy: 'bool | None' = None, fastpath: 'bool | lib.NoDefault' = <no_default>) -> 'None'

Liste des attributs statiques

Nom de l'attribut Valeur
index<pandas._libs.properties.AxisProperty object at 0x0000020D9B6DB9A0>

Attributs statiques hérités de la classe IndexOpsMixin

hasnans

Liste des propriétés

Nom de la propriétéDescription
array
at
attrs
axes
dtype
dtypes
empty
flags
hasnans
iat
iloc
is_monotonic_decreasing
is_monotonic_increasing
is_unique
loc
name
nbytes
ndim
shape
size
T
values

Liste des opérateurs

Signature de l'opérateur Description
__getitem__(self, key)
__matmul__(self, other)
__setitem__(self, key, value) -> 'None'

Opérateurs hérités de la classe NDFrame

__contains__, __delitem__, __iadd__, __iand__, __ifloordiv__, __imod__, __imul__, __invert__, __ior__, __ipow__, __isub__, __itruediv__, __ixor__, __neg__, __pos__

Opérateurs hérités de la classe OpsMixin

__add__, __and__, __eq__, __floordiv__, __ge__, __gt__, __le__, __lt__, __mod__, __mul__, __ne__, __or__, __pow__, __radd__, __rand__, __rfloordiv__, __rmod__, __rmul__, __ror__, __rpow__, __rsub__, __rtruediv__, __rxor__, __sub__, __truediv__, __xor__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__array__(self, dtype: 'npt.DTypeLike | None' = None, copy: 'bool | None' = None) -> 'np.ndarray'
__column_consortium_standard__(self, *, api_version: 'str | None' = None) -> 'Any'
__len__(self) -> 'int'
__repr__(self) -> 'str'
__rmatmul__(self, other)
add(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
agg(self, func=None, axis: 'Axis' = 0, *args, **kwargs)
aggregate(self, func=None, axis: 'Axis' = 0, *args, **kwargs)
all(self, axis: 'Axis' = 0, bool_only: 'bool' = False, skipna: 'bool' = True, **kwargs) -> 'bool'
any(self, *, axis: 'Axis' = 0, bool_only: 'bool' = False, skipna: 'bool' = True, **kwargs) -> 'bool'
apply(self, func: 'AggFuncType', convert_dtype: 'bool | lib.NoDefault' = <no_default>, args: 'tuple[Any, ...]' = (), *, by_row: "Literal[False, 'compat']" = 'compat', **kwargs) -> 'DataFrame | Series'
argsort(self, axis: 'Axis' = 0, kind: 'SortKind' = 'quicksort', order: 'None' = None, stable: 'None' = None) -> 'Series'
autocorr(self, lag: 'int' = 1) -> 'float'
between(self, left, right, inclusive: "Literal['both', 'neither', 'left', 'right']" = 'both') -> 'Series'
case_when(self, caselist: 'list[tuple[ArrayLike | Callable[[Series], Series | np.ndarray | Sequence[bool]], ArrayLike | Scalar | Callable[[Series], Series | np.ndarray]],]') -> 'Series'
combine(self, other: 'Series | Hashable', func: 'Callable[[Hashable, Hashable], Hashable]', fill_value: 'Hashable | None' = None) -> 'Series'
combine_first(self, other) -> 'Series'
compare(self, other: 'Series', align_axis: 'Axis' = 1, keep_shape: 'bool' = False, keep_equal: 'bool' = False, result_names: 'Suffixes' = ('self', 'other')) -> 'DataFrame | Series'
corr(self, other: 'Series', method: 'CorrelationMethod' = 'pearson', min_periods: 'int | None' = None) -> 'float'
count(self) -> 'int'
cov(self, other: 'Series', min_periods: 'int | None' = None, ddof: 'int | None' = 1) -> 'float'
cummax(self, axis: 'Axis | None' = None, skipna: 'bool' = True, *args, **kwargs)
cummin(self, axis: 'Axis | None' = None, skipna: 'bool' = True, *args, **kwargs)
cumprod(self, axis: 'Axis | None' = None, skipna: 'bool' = True, *args, **kwargs)
cumsum(self, axis: 'Axis | None' = None, skipna: 'bool' = True, *args, **kwargs)
diff(self, periods: 'int' = 1) -> 'Series'
div(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
divide(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
divmod(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
dot(self, other: 'AnyArrayLike') -> 'Series | np.ndarray'
drop(self, labels: 'IndexLabel | None' = None, *, axis: 'Axis' = 0, index: 'IndexLabel | None' = None, columns: 'IndexLabel | None' = None, level: 'Level | None' = None, inplace: 'bool' = False, errors: 'IgnoreRaise' = 'raise') -> 'Series | None'
drop_duplicates(self, *, keep: 'DropKeep' = 'first', inplace: 'bool' = False, ignore_index: 'bool' = False) -> 'Series | None'
dropna(self, *, axis: 'Axis' = 0, inplace: 'bool' = False, how: 'AnyAll | None' = None, ignore_index: 'bool' = False) -> 'Series | None'
duplicated(self, keep: 'DropKeep' = 'first') -> 'Series'
eq(self, other, level: 'Level | None' = None, fill_value: 'float | None' = None, axis: 'Axis' = 0) -> 'Series'
explode(self, ignore_index: 'bool' = False) -> 'Series'
floordiv(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
ge(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
groupby(self, by=None, axis: 'Axis' = 0, level: 'IndexLabel | None' = None, as_index: 'bool' = True, sort: 'bool' = True, group_keys: 'bool' = True, observed: 'bool | lib.NoDefault' = <no_default>, dropna: 'bool' = True) -> 'SeriesGroupBy'
gt(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
idxmax(self, axis: 'Axis' = 0, skipna: 'bool' = True, *args, **kwargs) -> 'Hashable'
idxmin(self, axis: 'Axis' = 0, skipna: 'bool' = True, *args, **kwargs) -> 'Hashable'
info(self, verbose: 'bool | None' = None, buf: 'IO[str] | None' = None, max_cols: 'int | None' = None, memory_usage: 'bool | str | None' = None, show_counts: 'bool' = True) -> 'None'
isin(self, values) -> 'Series'
isna(self) -> 'Series'
isnull(self) -> 'Series'
items(self) -> 'Iterable[tuple[Hashable, Any]]'
keys(self) -> 'Index'
kurt(self, axis: 'Axis | None' = 0, skipna: 'bool' = True, numeric_only: 'bool' = False, **kwargs)
kurtosis(self, axis: 'Axis | None' = 0, skipna: 'bool' = True, numeric_only: 'bool' = False, **kwargs)
le(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
lt(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
map(self, arg: 'Callable | Mapping | Series', na_action: "Literal['ignore'] | None" = None) -> 'Series'
max(self, axis: 'Axis | None' = 0, skipna: 'bool' = True, numeric_only: 'bool' = False, **kwargs)
mean(self, axis: 'Axis | None' = 0, skipna: 'bool' = True, numeric_only: 'bool' = False, **kwargs)
median(self, axis: 'Axis | None' = 0, skipna: 'bool' = True, numeric_only: 'bool' = False, **kwargs)
memory_usage(self, index: 'bool' = True, deep: 'bool' = False) -> 'int'
min(self, axis: 'Axis | None' = 0, skipna: 'bool' = True, numeric_only: 'bool' = False, **kwargs)
mod(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
mode(self, dropna: 'bool' = True) -> 'Series'
mul(self, other, level: 'Level | None' = None, fill_value: 'float | None' = None, axis: 'Axis' = 0) -> 'Series'
multiply(self, other, level: 'Level | None' = None, fill_value: 'float | None' = None, axis: 'Axis' = 0) -> 'Series'
ne(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
nlargest(self, n: 'int' = 5, keep: "Literal['first', 'last', 'all']" = 'first') -> 'Series'
notna(self) -> 'Series'
notnull(self) -> 'Series'
nsmallest(self, n: 'int' = 5, keep: "Literal['first', 'last', 'all']" = 'first') -> 'Series'
pop(self, item: 'Hashable') -> 'Any'
pow(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
prod(self, axis: 'Axis | None' = None, skipna: 'bool' = True, numeric_only: 'bool' = False, min_count: 'int' = 0, **kwargs)
product(self, axis: 'Axis | None' = None, skipna: 'bool' = True, numeric_only: 'bool' = False, min_count: 'int' = 0, **kwargs)
quantile(self, q: 'float | Sequence[float] | AnyArrayLike' = 0.5, interpolation: 'QuantileInterpolation' = 'linear') -> 'float | Series'
radd(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
ravel(self, order: 'str' = 'C') -> 'ArrayLike'
rdiv(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
rdivmod(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
reindex(self, index=None, *, axis: 'Axis | None' = None, method: 'ReindexMethod | None' = None, copy: 'bool | None' = None, level: 'Level | None' = None, fill_value: 'Scalar | None' = None, limit: 'int | None' = None, tolerance=None) -> 'Series'
rename(self, index: 'Renamer | Hashable | None' = None, *, axis: 'Axis | None' = None, copy: 'bool | None' = None, inplace: 'bool' = False, level: 'Level | None' = None, errors: 'IgnoreRaise' = 'ignore') -> 'Series | None'
rename_axis(self, mapper: 'IndexLabel | lib.NoDefault' = <no_default>, *, index=<no_default>, axis: 'Axis' = 0, copy: 'bool' = True, inplace: 'bool' = False) -> 'Self | None'
reorder_levels(self, order: 'Sequence[Level]') -> 'Series'
repeat(self, repeats: 'int | Sequence[int]', axis: 'None' = None) -> 'Series'
reset_index(self, level: 'IndexLabel | None' = None, *, drop: 'bool' = False, name: 'Level' = <no_default>, inplace: 'bool' = False, allow_duplicates: 'bool' = False) -> 'DataFrame | Series | None'
rfloordiv(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
rmod(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
rmul(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
round(self, decimals: 'int' = 0, *args, **kwargs) -> 'Series'
rpow(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
rsub(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
rtruediv(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
searchsorted(self, value: 'NumpyValueArrayLike | ExtensionArray', side: "Literal['left', 'right']" = 'left', sorter: 'NumpySorter | None' = None) -> 'npt.NDArray[np.intp] | np.intp'
sem(self, axis: 'Axis | None' = None, skipna: 'bool' = True, ddof: 'int' = 1, numeric_only: 'bool' = False, **kwargs)
set_axis(self, labels, *, axis: 'Axis' = 0, copy: 'bool | None' = None) -> 'Series'
skew(self, axis: 'Axis | None' = 0, skipna: 'bool' = True, numeric_only: 'bool' = False, **kwargs)
sort_index(self, *, axis: 'Axis' = 0, level: 'IndexLabel | None' = None, ascending: 'bool | Sequence[bool]' = True, inplace: 'bool' = False, kind: 'SortKind' = 'quicksort', na_position: 'NaPosition' = 'last', sort_remaining: 'bool' = True, ignore_index: 'bool' = False, key: 'IndexKeyFunc | None' = None) -> 'Series | None'
sort_values(self, *, axis: 'Axis' = 0, ascending: 'bool | Sequence[bool]' = True, inplace: 'bool' = False, kind: 'SortKind' = 'quicksort', na_position: 'NaPosition' = 'last', ignore_index: 'bool' = False, key: 'ValueKeyFunc | None' = None) -> 'Series | None'
std(self, axis: 'Axis | None' = None, skipna: 'bool' = True, ddof: 'int' = 1, numeric_only: 'bool' = False, **kwargs)
sub(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
subtract(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
sum(self, axis: 'Axis | None' = None, skipna: 'bool' = True, numeric_only: 'bool' = False, min_count: 'int' = 0, **kwargs)
swaplevel(self, i: 'Level' = -2, j: 'Level' = -1, copy: 'bool | None' = None) -> 'Series'
to_dict(self, *, into: 'type[MutableMappingT] | MutableMappingT' = <class 'dict'>) -> 'MutableMappingT'
to_frame(self, name: 'Hashable' = <no_default>) -> 'DataFrame'
to_markdown(self, buf: 'IO[str] | None' = None, mode: 'str' = 'wt', index: 'bool' = True, storage_options: 'StorageOptions | None' = None, **kwargs) -> 'str | None'
to_period(self, freq: 'str | None' = None, copy: 'bool | None' = None) -> 'Series'
to_string(self, buf: 'FilePath | WriteBuffer[str] | None' = None, na_rep: 'str' = 'NaN', float_format: 'str | None' = None, header: 'bool' = True, index: 'bool' = True, length: 'bool' = False, dtype: 'bool' = False, name: 'bool' = False, max_rows: 'int | None' = None, min_rows: 'int | None' = None) -> 'str | None'
to_timestamp(self, freq: 'Frequency | None' = None, how: "Literal['s', 'e', 'start', 'end']" = 'start', copy: 'bool | None' = None) -> 'Series'
transform(self, func: 'AggFuncType', axis: 'Axis' = 0, *args, **kwargs) -> 'DataFrame | Series'
truediv(self, other, level=None, fill_value=None, axis: 'Axis' = 0) -> 'Series'
unique(self) -> 'ArrayLike'
unstack(self, level: 'IndexLabel' = -1, fill_value: 'Hashable | None' = None, sort: 'bool' = True) -> 'DataFrame'
update(self, other: 'Series | Sequence | Mapping') -> 'None'
var(self, axis: 'Axis | None' = None, skipna: 'bool' = True, ddof: 'int' = 1, numeric_only: 'bool' = False, **kwargs)
view(self, dtype: 'Dtype | None' = None) -> 'Series'

Méthodes héritées de la classe NDFrame

__abs__, __array_ufunc__, __bool__, __copy__, __deepcopy__, __finalize__, __getattr__, __getstate__, __init_subclass__, __iter__, __nonzero__, __round__, __setattr__, __setstate__, __subclasshook__, abs, add_prefix, add_suffix, align, asfreq, asof, astype, at_time, backfill, between_time, bfill, bool, clip, convert_dtypes, copy, describe, droplevel, equals, ewm, expanding, ffill, fillna, filter, first, first_valid_index, get, head, infer_objects, interpolate, last, last_valid_index, mask, pad, pct_change, pipe, rank, reindex_like, replace, resample, rolling, sample, set_flags, shift, squeeze, swapaxes, tail, take, to_clipboard, to_csv, to_excel, to_hdf, to_json, to_latex, to_pickle, to_sql, to_xarray, truncate, tz_convert, tz_localize, where, xs

Méthodes héritées de la classe PandasObject

__sizeof__

Méthodes héritées de la classe DirNamesMixin

__dir__

Méthodes héritées de la classe IndexOpsMixin

argmax, argmin, factorize, item, nunique, to_list, to_numpy, tolist, transpose, value_counts

Méthodes héritées de la classe OpsMixin

__divmod__, __rdivmod__

Méthodes héritées de la classe object

__delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __str__

Vous êtes un professionnel et vous avez besoin d'une formation ? Calcul scientifique
avec Python
Voir le programme détaillé