- API reference
- Series
Series#
Constructor#
| One-dimensional ndarray with axis labels (including time series). |
Attributes#
Axes
The index (axis labels) of the Series. | |
The ExtensionArray of the data backing this Series or Index. | |
Return Series as ndarray or ndarray-like depending on the dtype. | |
Return the dtype object of the underlying data. | |
Return a tuple of the shape of the underlying data. | |
Return the number of bytes in the underlying data. | |
Number of dimensions of the underlying data, by definition 1. | |
Return the number of elements in the underlying data. | |
Return the transpose, which is by definition self. | |
| Return the memory usage of the Series. |
Return True if there are any NaNs. | |
Indicator whether Series/DataFrame is empty. | |
Return the dtype object of the underlying data. | |
Return the name of the Series. | |
Get the properties associated with this pandas object. | |
| Return a new object with updated flags. |
Conversion#
| Cast a pandas object to a specified dtype |
| Convert columns to the best possible dtypes using dtypes supporting |
| Attempt to infer better dtypes for object columns. |
| Make a copy of this object's indices and data. |
(DEPRECATED) Return the bool of a single element Series or DataFrame. | |
| A NumPy ndarray representing the values in this Series or Index. |
| Convert Series from DatetimeIndex to PeriodIndex. |
| Cast to DatetimeIndex of Timestamps, atbeginning of period. |
Return a list of the values. | |
| Return the values as a NumPy array. |
Indexing, iteration#
| Get item from object for given key (ex: DataFrame column). |
Access a single value for a row/column label pair. | |
Access a single value for a row/column pair by integer position. | |
Access a group of rows and columns by label(s) or a boolean array. | |
(DEPRECATED) Purely integer-location based indexing for selection by position. | |
Return an iterator of the values. | |
Lazily iterate over (index, value) tuples. | |
Return alias for index. | |
| Return item and drops from series. |
Return the first element of the underlying data as a Python scalar. | |
| Return cross-section from the Series/DataFrame. |
For more information on.at
,.iat
,.loc
, and.iloc
, see theindexing documentation.
Binary operator functions#
| Return Addition of series and other, element-wise (binary operatoradd). |
| Return Subtraction of series and other, element-wise (binary operatorsub). |
| Return Multiplication of series and other, element-wise (binary operatormul). |
| Return Floating division of series and other, element-wise (binary operatortruediv). |
| Return Floating division of series and other, element-wise (binary operatortruediv). |
| Return Integer division of series and other, element-wise (binary operatorfloordiv). |
| Return Modulo of series and other, element-wise (binary operatormod). |
| Return Exponential power of series and other, element-wise (binary operatorpow). |
| Return Addition of series and other, element-wise (binary operatorradd). |
| Return Subtraction of series and other, element-wise (binary operatorrsub). |
| Return Multiplication of series and other, element-wise (binary operatorrmul). |
| Return Floating division of series and other, element-wise (binary operatorrtruediv). |
| Return Floating division of series and other, element-wise (binary operatorrtruediv). |
| Return Integer division of series and other, element-wise (binary operatorrfloordiv). |
| Return Modulo of series and other, element-wise (binary operatorrmod). |
| Return Exponential power of series and other, element-wise (binary operatorrpow). |
| Combine the Series with a Series or scalar according tofunc. |
| Update null elements with value in the same location in 'other'. |
| Round each value in a Series to the given number of decimals. |
| Return Less than of series and other, element-wise (binary operatorlt). |
| Return Greater than of series and other, element-wise (binary operatorgt). |
| Return Less than or equal to of series and other, element-wise (binary operatorle). |
| Return Greater than or equal to of series and other, element-wise (binary operatorge). |
| Return Not equal to of series and other, element-wise (binary operatorne). |
| Return Equal to of series and other, element-wise (binary operatoreq). |
| Return the product of the values over the requested axis. |
| Compute the dot product between the Series and the columns of other. |
Function application, GroupBy & window#
| Invoke function on values of Series. |
| Aggregate using one or more operations over the specified axis. |
| Aggregate using one or more operations over the specified axis. |
| Call |
| Map values of Series according to an input mapping or function. |
| Group Series using a mapper or by a Series of columns. |
| Provide rolling window calculations. |
| Provide expanding window calculations. |
| Provide exponentially weighted (EW) calculations. |
| Apply chainable functions that expect Series or DataFrames. |
Computations / descriptive stats#
Return a Series/DataFrame with absolute numeric value of each element. | |
| Return whether all elements are True, potentially over an axis. |
| Return whether any element is True, potentially over an axis. |
| Compute the lag-N autocorrelation. |
| Return boolean Series equivalent to left <= series <= right. |
| Trim values at input threshold(s). |
| Compute correlation withother Series, excluding missing values. |
Return number of non-NA/null observations in the Series. | |
| Compute covariance with Series, excluding missing values. |
| Return cumulative maximum over a DataFrame or Series axis. |
| Return cumulative minimum over a DataFrame or Series axis. |
| Return cumulative product over a DataFrame or Series axis. |
| Return cumulative sum over a DataFrame or Series axis. |
| Generate descriptive statistics. |
| First discrete difference of element. |
| Encode the object as an enumerated type or categorical variable. |
| Return unbiased kurtosis over requested axis. |
| Return the maximum of the values over the requested axis. |
| Return the mean of the values over the requested axis. |
| Return the median of the values over the requested axis. |
| Return the minimum of the values over the requested axis. |
| Return the mode(s) of the Series. |
| Return the largestn elements. |
| Return the smallestn elements. |
| Fractional change between the current and a prior element. |
| Return the product of the values over the requested axis. |
| Return value at the given quantile. |
| Compute numerical data ranks (1 through n) along axis. |
| Return unbiased standard error of the mean over requested axis. |
| Return unbiased skew over requested axis. |
| Return sample standard deviation over requested axis. |
| Return the sum of the values over the requested axis. |
| Return unbiased variance over requested axis. |
| Return unbiased kurtosis over requested axis. |
Return unique values of Series object. | |
| Return number of unique elements in the object. |
Return boolean if values in the object are unique. | |
Return boolean if values in the object are monotonically increasing. | |
Return boolean if values in the object are monotonically decreasing. | |
| Return a Series containing counts of unique values. |
Reindexing / selection / label manipulation#
| Align two objects on their axes with the specified join method. |
| Replace values where the conditions are True. |
| Return Series with specified index labels removed. |
| Return Series/DataFrame with requested index / column level(s) removed. |
| Return Series with duplicate values removed. |
| Indicate duplicate Series values. |
| Test whether two objects contain the same elements. |
| (DEPRECATED) Select initial periods of time series data based on a date offset. |
| Return the firstn rows. |
| Return the row label of the maximum value. |
| Return the row label of the minimum value. |
| Whether elements in Series are contained invalues. |
| (DEPRECATED) Select final periods of time series data based on a date offset. |
| Conform Series to new index with optional filling logic. |
| Return an object with matching indices as other object. |
| Alter Series index labels or name. |
| Set the name of the axis for the index or columns. |
| Generate a new DataFrame or Series with the index reset. |
| Return a random sample of items from an axis of object. |
| Assign desired index to given axis. |
| Return the elements in the givenpositional indices along an axis. |
| Return the lastn rows. |
| Truncate a Series or DataFrame before and after some index value. |
| Replace values where the condition is False. |
| Replace values where the condition is True. |
| Prefix labels with stringprefix. |
| Suffix labels with stringsuffix. |
| Subset the dataframe rows or columns according to the specified index labels. |
Missing data handling#
| (DEPRECATED) Fill NA/NaN values by using the next valid observation to fill the gap. |
| Fill NA/NaN values by using the next valid observation to fill the gap. |
| Return a new Series with missing values removed. |
| Fill NA/NaN values by propagating the last valid observation to next valid. |
| Fill NA/NaN values using the specified method. |
| Fill NaN values using an interpolation method. |
Detect missing values. | |
Series.isnull is an alias for Series.isna. | |
Detect existing (non-missing) values. | |
Series.notnull is an alias for Series.notna. | |
| (DEPRECATED) Fill NA/NaN values by propagating the last valid observation to next valid. |
| Replace values given into_replace withvalue. |
Reshaping, sorting#
| Return the integer indices that would sort the Series values. |
| Return int position of the smallest value in the Series. |
| Return int position of the largest value in the Series. |
| Rearrange index levels using input order. |
| Sort by the values. |
| Sort Series by index labels. |
| Swap levels i and j in a |
| Unstack, also known as pivot, Series with MultiIndex to produce DataFrame. |
| Transform each element of a list-like to a row. |
| Find indices where elements should be inserted to maintain order. |
| (DEPRECATED) Return the flattened underlying data as an ndarray or ExtensionArray. |
| Repeat elements of a Series. |
| Squeeze 1 dimensional axis objects into scalars. |
| (DEPRECATED) Create a new view of the Series. |
Combining / comparing / joining / merging#
| Compare to another Series and show the differences. |
| Modify Series in place using values from passed Series. |
Time Series-related#
| Convert time series to specified frequency. |
| Return the last row(s) without any NaNs beforewhere. |
| Shift index by desired number of periods with an optional timefreq. |
Return index for first non-NA value or None, if no non-NA value is found. | |
Return index for last non-NA value or None, if no non-NA value is found. | |
| Resample time-series data. |
| Convert tz-aware axis to target time zone. |
| Localize tz-naive index of a Series or DataFrame to target time zone. |
| Select values at particular time of day (e.g., 9:30AM). |
| Select values between particular times of the day (e.g., 9:00-9:30 AM). |
Accessors#
pandas provides dtype-specific methods under various accessors.These are separate namespaces withinSeries
that only applyto specific data types.
alias of | |
alias of | |
alias of | |
alias of | |
alias of | |
alias of |
Data Type | Accessor |
---|---|
Datetime, Timedelta, Period | |
String | |
Categorical | |
Sparse |
Datetimelike properties#
Series.dt
can be used to access the values of the series asdatetimelike and return several properties.These can be accessed likeSeries.dt.<property>
.
Datetime properties#
Returns numpy array of python | |
Returns numpy array of | |
Returns numpy array of | |
The year of the datetime. | |
The month as January=1, December=12. | |
The day of the datetime. | |
The hours of the datetime. | |
The minutes of the datetime. | |
The seconds of the datetime. | |
The microseconds of the datetime. | |
The nanoseconds of the datetime. | |
The day of the week with Monday=0, Sunday=6. | |
The day of the week with Monday=0, Sunday=6. | |
The day of the week with Monday=0, Sunday=6. | |
The ordinal day of the year. | |
The ordinal day of the year. | |
The number of days in the month. | |
The quarter of the date. | |
Indicates whether the date is the first day of the month. | |
Indicates whether the date is the last day of the month. | |
Indicator for whether the date is the first day of a quarter. | |
Indicator for whether the date is the last day of a quarter. | |
Indicate whether the date is the first day of a year. | |
Indicate whether the date is the last day of the year. | |
Boolean indicator if the date belongs to a leap year. | |
The number of days in the month. | |
The number of days in the month. | |
Return the timezone. | |
Return the frequency object for this PeriodArray. | |
Datetime methods#
Calculate year, week, and day according to the ISO 8601 standard. | |
| Cast to PeriodArray/PeriodIndex at a particular frequency. |
(DEPRECATED) Return the data as an array of | |
| Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index. |
| Convert tz-aware Datetime Array/Index from one time zone to another. |
| Convert times to midnight. |
| Convert to Index using specified date_format. |
| Perform round operation on the data to the specifiedfreq. |
| Perform floor operation on the data to the specifiedfreq. |
| Perform ceil operation on the data to the specifiedfreq. |
| Return the month names with specified locale. |
| Return the day names with specified locale. |
|
Period properties#
Get the Timestamp for the start of the period. | |
Get the Timestamp for the end of the period. |
Timedelta properties#
Number of days for each element. | |
Number of seconds (>= 0 and less than 1 day) for each element. | |
Number of microseconds (>= 0 and less than 1 second) for each element. | |
Number of nanoseconds (>= 0 and less than 1 microsecond) for each element. | |
Return a Dataframe of the components of the Timedeltas. | |
Timedelta methods#
Return an array of native | |
| Return total duration of each element expressed in seconds. |
|
String handling#
Series.str
can be used to access the values of the series asstrings and apply several methods to it. These can be accessed likeSeries.str.<function/property>
.
Convert strings in the Series/Index to be capitalized. | |
Convert strings in the Series/Index to be casefolded. | |
| Concatenate strings in the Series/Index with given separator. |
| Pad left and right side of strings in the Series/Index. |
| Test if pattern or regex is contained within a string of a Series or Index. |
| Count occurrences of pattern in each string of the Series/Index. |
| Decode character string in the Series/Index using indicated encoding. |
| Encode character string in the Series/Index using indicated encoding. |
| Test if the end of each string element matches a pattern. |
| Extract capture groups in the regexpat as columns in a DataFrame. |
| Extract capture groups in the regexpat as columns in DataFrame. |
| Return lowest indexes in each strings in the Series/Index. |
| Find all occurrences of pattern or regular expression in the Series/Index. |
| Determine if each string entirely matches a regular expression. |
Extract element from each component at specified position or with specified key. | |
| Return lowest indexes in each string in Series/Index. |
| Join lists contained as elements in the Series/Index with passed delimiter. |
Compute the length of each element in the Series/Index. | |
| Pad right side of strings in the Series/Index. |
Convert strings in the Series/Index to lowercase. | |
| Remove leading characters. |
| Determine if each string starts with a match of a regular expression. |
| Return the Unicode normal form for the strings in the Series/Index. |
| Pad strings in the Series/Index up to width. |
| Split the string at the first occurrence ofsep. |
| Remove a prefix from an object series. |
| Remove a suffix from an object series. |
| Duplicate each string in the Series or Index. |
| Replace each occurrence of pattern/regex in the Series/Index. |
| Return highest indexes in each strings in the Series/Index. |
| Return highest indexes in each string in Series/Index. |
| Pad left side of strings in the Series/Index. |
| Split the string at the last occurrence ofsep. |
| Remove trailing characters. |
| Slice substrings from each element in the Series or Index. |
| Replace a positional slice of a string with another value. |
| Split strings around given separator/delimiter. |
| Split strings around given separator/delimiter. |
| Test if the start of each string element matches a pattern. |
| Remove leading and trailing characters. |
Convert strings in the Series/Index to be swapcased. | |
Convert strings in the Series/Index to titlecase. | |
| Map all characters in the string through the given mapping table. |
Convert strings in the Series/Index to uppercase. | |
| Wrap strings in Series/Index at specified line width. |
| Pad strings in the Series/Index by prepending '0' characters. |
Check whether all characters in each string are alphanumeric. | |
Check whether all characters in each string are alphabetic. | |
Check whether all characters in each string are digits. | |
Check whether all characters in each string are whitespace. | |
Check whether all characters in each string are lowercase. | |
Check whether all characters in each string are uppercase. | |
Check whether all characters in each string are titlecase. | |
Check whether all characters in each string are numeric. | |
Check whether all characters in each string are decimal. | |
| Return DataFrame of dummy/indicator variables for Series. |
Categorical accessor#
Categorical-dtype specific methods and attributes are available undertheSeries.cat
accessor.
The categories of this categorical. | |
Whether the categories have an ordered relationship. | |
Return Series of codes as well as the index. |
| Rename categories. |
| Reorder categories as specified in new_categories. |
| Add new categories. |
| Remove the specified categories. |
| Remove categories which are not used. |
| Set the categories to the specified new categories. |
| Set the Categorical to be ordered. |
| Set the Categorical to be unordered. |
Sparse accessor#
Sparse-dtype specific methods and attributes are provided under theSeries.sparse
accessor.
The number of non- | |
The percent of non- | |
Elements indata that arefill_value are not stored. | |
An ndarray containing the non- |
| Create a Series with sparse values from a scipy.sparse.coo_matrix. |
| Create a scipy.sparse.coo_matrix from a Series with MultiIndex. |
List accessor#
Arrow list-dtype specific methods and attributes are provided under theSeries.list
accessor.
Flatten list values. | |
Return the length of each list in the Series. | |
Index or slice lists in the Series. |
Struct accessor#
Arrow struct-dtype specific methods and attributes are provided under theSeries.struct
accessor.
Return the dtype object of each child field of the struct. |
| Extract a child field of a struct as a Series. |
Extract all child fields of a struct as a DataFrame. |
Flags#
Flags refer to attributes of the pandas object. Properties of the dataset (likethe date is was recorded, the URL it was accessed from, etc.) should be storedinSeries.attrs
.
| Flags that apply to pandas objects. |
Metadata#
Series.attrs
is a dictionary for storing global metadata for this Series.
Warning
Series.attrs
is considered experimental and may change without warning.
Dictionary of global attributes of this dataset. |
Plotting#
Series.plot
is both a callable method and a namespace attribute forspecific plotting methods of the formSeries.plot.<kind>
.
| Series plotting accessor and method |
| Draw a stacked area plot. |
| Vertical bar plot. |
| Make a horizontal bar plot. |
| Make a box plot of the DataFrame columns. |
| Generate Kernel Density Estimate plot using Gaussian kernels. |
| Draw one histogram of the DataFrame's columns. |
| Generate Kernel Density Estimate plot using Gaussian kernels. |
| Plot Series or DataFrame as lines. |
| Generate a pie plot. |
| Draw histogram of the input series using matplotlib. |
Serialization / IO / conversion#
| Pickle (serialize) object to file. |
| Write object to a comma-separated values (csv) file. |
| Convert Series to {label -> value} dict or dict-like object. |
| Write object to an Excel sheet. |
| Convert Series to DataFrame. |
Return an xarray object from the pandas object. | |
| Write the contained data to an HDF5 file using HDFStore. |
| Write records stored in a DataFrame to a SQL database. |
| Convert the object to a JSON string. |
| Render a string representation of the Series. |
| Copy object to the system clipboard. |
| Render object to a LaTeX tabular, longtable, or nested table. |
| Print Series in Markdown-friendly format. |
- Constructor
- Attributes
- Conversion
- Indexing, iteration
- Binary operator functions
- Function application, GroupBy & window
- Computations / descriptive stats
- Reindexing / selection / label manipulation
- Missing data handling
- Reshaping, sorting
- Combining / comparing / joining / merging
- Time Series-related
- Accessors
- Plotting
- Serialization / IO / conversion