Series — pandas 0.24.2 documentation (original) (raw)
Constructor¶
Series([data, index, dtype, name, copy, …]) | One-dimensional ndarray with axis labels (including time series). |
---|
Conversion¶
Series.astype(dtype[, copy, errors]) | Cast a pandas object to a specified dtype dtype. |
---|---|
Series.infer_objects() | Attempt to infer better dtypes for object columns. |
Series.convert_objects([convert_dates, …]) | (DEPRECATED) Attempt to infer better dtype for object columns. |
Series.copy([deep]) | Make a copy of this object’s indices and data. |
Series.bool() | Return the bool of a single element PandasObject. |
Series.to_numpy([dtype, copy]) | A NumPy ndarray representing the values in this Series or Index. |
Series.to_period([freq, copy]) | Convert Series from DatetimeIndex to PeriodIndex with desired frequency (inferred from index if not passed). |
Series.to_timestamp([freq, how, copy]) | Cast to datetimeindex of timestamps, at beginning of period. |
Series.to_list() | Return a list of the values. |
Series.get_values() | Same as values (but handles sparseness conversions); is a view. |
Series.__array__([dtype]) | Return the values as a NumPy array. |
Indexing, iteration¶
Series.get(key[, default]) | Get item from object for given key (DataFrame column, Panel slice, etc.). |
---|---|
Series.at | Access a single value for a row/column label pair. |
Series.iat | Access a single value for a row/column pair by integer position. |
Series.loc | Access a group of rows and columns by label(s) or a boolean array. |
Series.iloc | Purely integer-location based indexing for selection by position. |
Series.__iter__() | Return an iterator of the values. |
Series.iteritems() | Lazily iterate over (index, value) tuples. |
Series.items() | Lazily iterate over (index, value) tuples. |
Series.keys() | Alias for index. |
Series.pop(item) | Return item and drop from frame. |
Series.item() | Return the first element of the underlying data as a python scalar. |
Series.xs(key[, axis, level, drop_level]) | Return cross-section from the Series/DataFrame. |
For more information on .at
, .iat
, .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]) | Combine the Series with a Series or scalar according to func. |
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[, level, fill_value, axis]) | Less than of series and other, element-wise (binary operator lt). |
Series.gt(other[, level, fill_value, axis]) | Greater than of series and other, element-wise (binary operator gt). |
Series.le(other[, level, fill_value, axis]) | Less than or equal to of series and other, element-wise (binary operator le). |
Series.ge(other[, level, fill_value, axis]) | Greater than or equal to of series and other, element-wise (binary operator ge). |
Series.ne(other[, level, fill_value, axis]) | Not equal to of series and other, element-wise (binary operator ne). |
Series.eq(other[, level, fill_value, axis]) | Equal to of series and other, element-wise (binary operator eq). |
Series.product([axis, skipna, level, …]) | Return the product of the values for the requested axis. |
Series.dot(other) | Compute the dot product between the Series and the columns of other. |
Function application, GroupBy & Window¶
Series.apply(func[, convert_dtype, args]) | Invoke function on values of Series. |
---|---|
Series.agg(func[, axis]) | Aggregate using one or more operations over the specified axis. |
Series.aggregate(func[, axis]) | Aggregate using one or more operations over the specified axis. |
Series.transform(func[, axis]) | Call func on self producing a Series with transformed values and that has the same axis length as self. |
Series.map(arg[, na_action]) | Map values of Series according to input correspondence. |
Series.groupby([by, axis, level, as_index, …]) | Group DataFrame or Series using a mapper or by a Series of columns. |
Series.rolling(window[, min_periods, …]) | Provides rolling window calculations. |
Series.expanding([min_periods, center, axis]) | Provides expanding transformations. |
Series.ewm([com, span, halflife, alpha, …]) | Provides exponential weighted functions. |
Series.pipe(func, *args, **kwargs) | Apply func(self, *args, **kwargs). |
Computations / Descriptive Stats¶
Series.abs() | Return a Series/DataFrame with absolute numeric value of each element. |
---|---|
Series.all([axis, bool_only, skipna, level]) | Return whether all elements are True, potentially over an axis. |
Series.any([axis, bool_only, skipna, level]) | Return whether any element is True, potentially over an axis. |
Series.autocorr([lag]) | Compute the lag-N autocorrelation. |
Series.between(left, right[, inclusive]) | Return boolean Series equivalent to left <= series <= right. |
Series.clip([lower, upper, axis, inplace]) | Trim values at input threshold(s). |
Series.clip_lower(threshold[, axis, inplace]) | (DEPRECATED) Trim values below a given threshold. |
Series.clip_upper(threshold[, axis, inplace]) | (DEPRECATED) Trim values above a given threshold. |
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 maximum over a DataFrame or Series axis. |
Series.cummin([axis, skipna]) | Return cumulative minimum over a DataFrame or Series axis. |
Series.cumprod([axis, skipna]) | Return cumulative product over a DataFrame or Series axis. |
Series.cumsum([axis, skipna]) | Return cumulative sum over a DataFrame or Series axis. |
Series.describe([percentiles, include, exclude]) | Generate descriptive statistics that summarize the central tendency, dispersion and shape of a dataset’s distribution, excluding NaN values. |
Series.diff([periods]) | First discrete difference of element. |
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]) | Return the maximum of the values for the requested axis. |
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]) | Return the minimum of the values for the requested axis. |
Series.mode([dropna]) | Return the mode(s) of the dataset. |
Series.nlargest([n, keep]) | Return the largest n elements. |
Series.nsmallest([n, keep]) | Return the smallest n elements. |
Series.pct_change([periods, fill_method, …]) | Percentage change between the current and a prior element. |
Series.prod([axis, skipna, level, …]) | Return the product of the values for the requested axis. |
Series.quantile([q, interpolation]) | Return value at the given quantile. |
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 Normalized by N-1. |
Series.std([axis, skipna, level, ddof, …]) | Return sample standard deviation over requested axis. |
Series.sum([axis, skipna, level, …]) | Return the sum of the values for the requested axis. |
Series.var([axis, skipna, level, ddof, …]) | Return unbiased variance over requested axis. |
Series.kurtosis([axis, skipna, level, …]) | Return unbiased kurtosis over requested axis using Fisher’s definition of kurtosis (kurtosis of normal == 0.0). |
Series.unique() | Return unique values of Series 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 monotonic_increasing. |
Series.is_monotonic_increasing | Return boolean if values in the object are monotonic_increasing. |
Series.is_monotonic_decreasing | Return boolean if values in the object are monotonic_decreasing. |
Series.value_counts([normalize, sort, …]) | Return a Series containing counts of unique values. |
Series.compound([axis, skipna, level]) | Return the compound percentage of the values for the requested axis. |
Reindexing / Selection / Label manipulation¶
Series.align(other[, join, axis, level, …]) | Align two objects on their axes with the specified join method for each axis Index. |
---|---|
Series.drop([labels, axis, index, columns, …]) | Return Series with specified index labels removed. |
Series.droplevel(level[, axis]) | Return DataFrame with requested index / column level(s) removed. |
Series.drop_duplicates([keep, inplace]) | Return Series with duplicate values removed. |
Series.duplicated([keep]) | Indicate duplicate Series values. |
Series.equals(other) | Test whether two 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]) | Return the first n rows. |
Series.idxmax([axis, skipna]) | Return the row label of the maximum value. |
Series.idxmin([axis, skipna]) | Return the row label of the minimum value. |
Series.isin(values) | Check whether values are contained in Series. |
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 as other object. |
Series.rename([index]) | Alter Series index labels or name. |
Series.rename_axis([mapper, index, columns, …]) | Set the name of the axis for the index or columns. |
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.select(crit[, axis]) | (DEPRECATED) Return data corresponding to axis labels matching criteria. |
Series.set_axis(labels[, axis, inplace]) | Assign desired index to given axis. |
Series.take(indices[, axis, convert, is_copy]) | Return the elements in the given positional indices along an axis. |
Series.tail([n]) | Return the last n rows. |
Series.truncate([before, after, axis, copy]) | Truncate a Series or DataFrame before and after some index value. |
Series.where(cond[, other, inplace, axis, …]) | Replace values where the condition is False. |
Series.mask(cond[, other, inplace, axis, …]) | Replace values where the condition is True. |
Series.add_prefix(prefix) | Prefix labels with string prefix. |
Series.add_suffix(suffix) | Suffix labels with string suffix. |
Series.filter([items, like, regex, axis]) | Subset rows or columns of dataframe according to labels in the specified index. |
Missing data handling¶
Series.isna() | Detect missing values. |
---|---|
Series.notna() | Detect existing (non-missing) values. |
Series.dropna([axis, inplace]) | Return a new Series with missing values removed. |
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.argmin([axis, skipna]) | (DEPRECATED) Return the row label of the minimum value. |
Series.argmax([axis, skipna]) | (DEPRECATED) Return the row label of the maximum value. |
Series.reorder_levels(order) | Rearrange index levels using input order. |
Series.sort_values([axis, ascending, …]) | Sort by the values. |
Series.sort_index([axis, level, ascending, …]) | Sort Series by index labels. |
Series.swaplevel([i, j, copy]) | Swap levels i and j in a MultiIndex. |
Series.unstack([level, fill_value]) | Unstack, a.k.a. |
Series.searchsorted(value[, side, sorter]) | Find indices where elements should be inserted to maintain order. |
Series.ravel([order]) | Return the flattened underlying data as an ndarray. |
Series.repeat(repeats[, axis]) | Repeat elements of a Series. |
Series.squeeze([axis]) | Squeeze 1 dimensional axis objects into scalars. |
Series.view([dtype]) | Create a new view of the Series. |
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. |
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 |
Categorical | cat |
Sparse | sparse |
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 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 native Python 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 of the DateTimeIndex with specified locale. |
Series.dt.day_name(*args, **kwargs) | Return the day names of the DateTimeIndex 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 likeSeries.str.<function/property>
.
Series.str.capitalize() | Convert strings in the Series/Index to be capitalized. |
---|---|
Series.str.cat([others, sep, na_rep, join]) | 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, …]) | 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.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]) | Test if the end of each string element matches a pattern. |
Series.str.extract(pat[, flags, expand]) | Extract capture groups in the regex pat as columns in a DataFrame. |
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 each component at specified position. |
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() | Computes the length of each element 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]) | Remove leading and trailing characters. |
Series.str.match(pat[, case, flags, na]) | Determine if each string matches a 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 up to width. |
Series.str.partition([sep, expand]) | Split the string at the first occurrence of sep. |
Series.str.repeat(repeats) | Duplicate each string in the Series or Index. |
Series.str.replace(pat, repl[, n, case, …]) | 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([sep, expand]) | Split the string at the last occurrence of sep. |
Series.str.rstrip([to_strip]) | Remove leading and trailing characters. |
Series.str.slice([start, stop, step]) | Slice substrings from each element in the Series or Index. |
Series.str.slice_replace([start, stop, repl]) | Replace a positional slice of a string with another value. |
Series.str.split([pat, n, expand]) | Split strings around given separator/delimiter. |
Series.str.rsplit([pat, n, expand]) | Split strings around given separator/delimiter. |
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[, 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) | 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. |
Series.str.get_dummies([sep]) | Split each string in the Series by sep and return a frame of dummy/indicator variables. |
Serialization / IO / Conversion¶
Series.to_pickle(path[, compression, protocol]) | Pickle (serialize) object to file. |
---|---|
Series.to_csv(*args, **kwargs) | Write object to a comma-separated values (csv) file. |
Series.to_dict([into]) | Convert Series to {label -> value} dict or dict-like object. |
Series.to_excel(excel_writer[, sheet_name, …]) | Write object to an Excel sheet. |
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) | Write the contained data to an HDF5 file using HDFStore. |
Series.to_sql(name, con[, schema, …]) | Write records stored in a DataFrame to a SQL database. |
Series.to_msgpack([path_or_buf, encoding]) | Serialize object to input file path using msgpack format. |
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]) | Copy object to the system clipboard. |
Series.to_latex([buf, columns, col_space, …]) | Render an object to a LaTeX tabular environment table. |
Sparse¶
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. |