Return index of first occurrence of minimum over requested axis.
NA/null values are excluded.
The axis to use. 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise.
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
Indexes of minima along the specified axis.
If the row/column is empty
See also
Return index of the minimum element.
Notes
This method is the DataFrame version of ndarray.argmin.
Examples
Consider a dataset containing food consumption in Argentina.
By default, it returns the index for the minimum value in each column.
To return the index for the minimum value in each row, use axis="columns".


Purely integer-location based indexing for selection by position.
.iloc[] is primarily integer position based (from 0 to length-1 of the axis), but may also be used with a boolean array.
Allowed inputs are:
An integer, e.g. 5.
A list or array of integers, e.g. [4, 3, 0].
A slice object with ints, e.g. 1:7.
A boolean array.
A callable function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above). This is useful in method chains, when you don’t have a reference to the calling object, but would like to base your selection on some value.
.iloc will raise IndexError if a requested indexer is out-of-bounds, except slice indexers which allow out-of-bounds indexing (this conforms with python/numpy slice semantics).
See more at Selection by Position.
See also
Fast integer location scalar accessor.
Purely label-location based indexer for selection by label.
Purely integer-location based indexing for selection by position.
Examples
Indexing just the rows
With a scalar integer.
With a list of integers.
With a slice object.
With a boolean mask the same length as the index.
With a callable, useful in method chains. The x passed to the lambda is the DataFrame being sliced. This selects the rows whose index label even.
Indexing both axes
You can mix the indexer types for the index and columns. Use : to select the entire axis.
With scalar integers.
With lists of integers.
With slice objects.
With a boolean array whose length matches the columns.
With a callable function that expects the Series or DataFrame.


The index (row labels) of the DataFrame.


Attempt to infer better dtypes for object columns.
Attempts soft conversion of object-dtyped columns, leaving non-object and unconvertible columns unchanged. The inference rules are the same as during normal Series/DataFrame construction.
See also
Convert argument to datetime.
Convert argument to timedelta.
Convert argument to numeric type.
Convert argument to best possible dtype.
Examples


Print a concise summary of a DataFrame.
This method prints information about a DataFrame including the index dtype and columns, non-null values and memory usage.
DataFrame to print information about.
Whether to print the full summary. By default, the setting in pandas.options.display.max_info_columns is followed.
Where to send the output. By default, the output is printed to sys.stdout. Pass a writable buffer if you need to further process the output. max_cols : int, optional When to switch from the verbose to the truncated output. If the DataFrame has more than max_cols columns, the truncated output is used. By default, the setting in pandas.options.display.max_info_columns is used.
Specifies whether total memory usage of the DataFrame elements (including the index) should be displayed. By default, this follows the pandas.options.display.memory_usage setting.
True always show memory usage. False never shows memory usage. A value of ‘deep’ is equivalent to “True with deep introspection”. Memory usage is shown in human-readable units (base-2 representation). Without deep introspection a memory estimation is made based in column dtype and number of rows assuming values consume the same memory amount for corresponding dtypes. With deep memory introspection, a real memory usage calculation is performed at the cost of computational resources.
Whether to show the non-null counts. By default, this is shown only if the DataFrame is smaller than pandas.options.display.max_info_rows and pandas.options.display.max_info_columns. A value of True always shows the counts, and False never shows the counts.
Deprecated since version 1.2.0: Use show_counts instead.
This method prints a summary of a DataFrame and returns None.
See also
Generate descriptive statistics of DataFrame columns.
Memory usage of DataFrame columns.
Examples
Prints information of all columns:
Prints a summary of columns count and its dtypes but not per column information:
Pipe output of DataFrame.info to buffer instead of sys.stdout, get buffer content and writes to a text file:
The memory_usage parameter allows deep introspection mode, specially useful for big DataFrames and fine-tune memory optimization:


Insert column into DataFrame at specified location.
Raises a ValueError if column is already contained in the DataFrame, unless allow_duplicates is set to True.
Insertion index. Must verify 0 <= loc <= len(columns).
Label of the inserted column.
See also
Insert new item by index.
Examples
Notice that pandas uses index alignment in case of value from type Series:


Fill NaN values using an interpolation method.
Please note that only method='linear' is supported for DataFrame/Series with a MultiIndex.
Interpolation technique to use. One of:
‘linear’: Ignore the index and treat the values as equally spaced. This is the only method supported on MultiIndexes.
‘time’: Works on daily and higher resolution data to interpolate given length of interval.
‘index’, ‘values’: use the actual numerical values of the index.
‘pad’: Fill in NaNs using existing values.
‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’, ‘spline’, ‘barycentric’, ‘polynomial’: Passed to scipy.interpolate.interp1d. These methods use the numerical values of the index. Both ‘polynomial’ and ‘spline’ require that you also specify an order (int), e.g. df.interpolate(method='polynomial', order=5).
‘krogh’, ‘piecewise_polynomial’, ‘spline’, ‘pchip’, ‘akima’, ‘cubicspline’: Wrappers around the SciPy interpolation methods of similar names. See Notes.
‘from_derivatives’: Refers to scipy.interpolate.BPoly.from_derivatives which replaces ‘piecewise_polynomial’ interpolation method in scipy 0.18.
Axis to interpolate along.
Maximum number of consecutive NaNs to fill. Must be greater than 0.
Update the data in place if possible.
Consecutive NaNs will be filled in this direction.
If ‘method’ is ‘pad’ or ‘ffill’, ‘limit_direction’ must be ‘forward’.
If ‘method’ is ‘backfill’ or ‘bfill’, ‘limit_direction’ must be ‘backwards’.
If ‘method’ is ‘backfill’ or ‘bfill’, the default is ‘backward’
else the default is ‘forward’
Changed in version 1.1.0: raises ValueError if limit_direction is ‘forward’ or ‘both’ and method is ‘backfill’ or ‘bfill’. raises ValueError if limit_direction is ‘backward’ or ‘both’ and method is ‘pad’ or ‘ffill’.
If limit is specified, consecutive NaNs will be filled with this restriction.
None: No fill restriction.
‘inside’: Only fill NaNs surrounded by valid values (interpolate).
‘outside’: Only fill NaNs outside valid values (extrapolate).
Downcast dtypes if possible.
Keyword arguments to pass on to the interpolating function.
Returns the same object type as the caller, interpolated at some or all NaN values or None if inplace=True.
See also
Fill missing values using different methods.
Piecewise cubic polynomials (Akima interpolator).
Piecewise polynomial in the Bernstein basis.
Interpolate a 1-D function.
Interpolate polynomial (Krogh interpolator).
PCHIP 1-d monotonic cubic interpolation.
Cubic spline data interpolator.
Notes
The ‘krogh’, ‘piecewise_polynomial’, ‘spline’, ‘pchip’ and ‘akima’ methods are wrappers around the respective SciPy implementations of similar names. These use the actual numerical values of the index. For more information on their behavior, see the SciPy documentation and SciPy tutorial.
Examples
Filling in NaN in a Series via linear interpolation.
Filling in NaN in a Series by padding, but filling at most two consecutive NaN at a time.
Filling in NaN in a Series via polynomial interpolation or splines: Both ‘polynomial’ and ‘spline’ methods require that you also specify an order (int).
Fill the DataFrame forward (that is, going down) along each column using linear interpolation.
Note how the last entry in column ‘a’ is interpolated differently, because there is no entry after it to use for interpolation. Note how the first entry in column ‘b’ remains NaN, because there is no entry before it to use for interpolation.
Using polynomial interpolation.


Whether each element in the DataFrame is contained in values.
The result will only be true at a location if all the labels match. If values is a Series, that’s the index. If values is a dict, the keys must be the column names, which must match. If values is a DataFrame, then both the index and column labels must match.
DataFrame of booleans showing whether each element in the DataFrame is contained in values.
See also
Equality test for DataFrame.
Equivalent method on Series.
Test if pattern or regex is contained within a string of a Series or Index.
Examples
When values is a list check whether every value in the DataFrame is present in the list (which animals have 0 or 2 legs or wings)
To check if values is not in the DataFrame, use the ~ operator:
When values is a dict, we can pass values to check for each column separately:
When values is a Series or DataFrame the index and column must match. Note that ‘falcon’ does not match based on the number of legs in other.


Detect missing values.
Return a boolean same-sized object indicating if the values are NA. NA values, such as None or numpy.NaN, gets mapped to True values. Everything else gets mapped to False values. Characters such as empty strings '' or numpy.inf are not considered NA values (unless you set pandas.options.mode.use_inf_as_na = True).
Mask of bool values for each element in DataFrame that indicates whether an element is an NA value.
See also
Alias of isna.
Boolean inverse of isna.
Omit axes labels with missing values.
Top-level isna.
Examples
Show which entries in a DataFrame are NA.
Show which entries in a Series are NA.


DataFrame.isnull is an alias for DataFrame.isna.
Detect missing values.
Return a boolean same-sized object indicating if the values are NA. NA values, such as None or numpy.NaN, gets mapped to True values. Everything else gets mapped to False values. Characters such as empty strings '' or numpy.inf are not considered NA values (unless you set pandas.options.mode.use_inf_as_na = True).
Mask of bool values for each element in DataFrame that indicates whether an element is an NA value.
See also
Alias of isna.
Boolean inverse of isna.
Omit axes labels with missing values.
Top-level isna.
Examples
Show which entries in a DataFrame are NA.
Show which entries in a Series are NA.


Iterate over (column name, Series) pairs.
Iterates over the DataFrame columns, returning a tuple with the column name and the content as a Series.
The column names for the DataFrame being iterated over.
The column entries belonging to each label, as a Series.
See also
Iterate over DataFrame rows as (index, Series) pairs.
Iterate over DataFrame rows as namedtuples of the values.
Examples


Iterate over DataFrame rows as (index, Series) pairs.
The index of the row. A tuple for a MultiIndex.
The data of the row as a Series.
See also
Iterate over DataFrame rows as namedtuples of the values.
Iterate over (column name, Series) pairs.
Notes
Because iterrows returns a Series for each row, it does not preserve dtypes across the rows (dtypes are preserved across columns for DataFrames). For example,
To preserve dtypes while iterating over the rows, it is better to use itertuples() which returns namedtuples of the values and which is generally faster than iterrows.
You should never modify something you are iterating over. This is not guaranteed to work in all cases. Depending on the data types, the iterator returns a copy and not a view, and writing to it will have no effect.


Iterate over DataFrame rows as namedtuples.
If True, return the index as the first element of the tuple.
The name of the returned namedtuples or None to return regular tuples.
An object to iterate over namedtuples for each row in the DataFrame with the first field possibly being the index and following fields being the column values.
See also
Iterate over DataFrame rows as (index, Series) pairs.
Iterate over (column name, Series) pairs.
Notes
The column names will be renamed to positional names if they are invalid Python identifiers, repeated, or start with an underscore. On python versions < 3.7 regular tuples are returned for DataFrames with a large number of columns (>254).
Examples
By setting the index parameter to False we can remove the index as the first element of the tuple:
With the name parameter set we set a custom name for the yielded namedtuples:


Join columns of another DataFrame.
Join columns with other DataFrame either on index or on a key column. Efficiently join multiple DataFrame objects by index at once by passing a list.
Index should be similar to one of the columns in this one. If a Series is passed, its name attribute must be set, and that will be used as the column name in the resulting joined DataFrame.
Column or index level name(s) in the caller to join on the index in other, otherwise joins index-on-index. If multiple values given, the other DataFrame must have a MultiIndex. Can pass an array as the join key if it is not already contained in the calling DataFrame. Like an Excel VLOOKUP operation.
How to handle the operation of the two objects.
left: use calling frame’s index (or column if on is specified)
right: use other’s index.
outer: form union of calling frame’s index (or column if on is specified) with other’s index, and sort it. lexicographically.
inner: form intersection of calling frame’s index (or column if on is specified) with other’s index, preserving the order of the calling’s one.
cross: creates the cartesian product from both frames, preserves the order of the left keys.
New in version 1.2.0.
Suffix to use from left frame’s overlapping columns.
Suffix to use from right frame’s overlapping columns.
Order result DataFrame lexicographically by the join key. If False, the order of the join key depends on the join type (how keyword).
A dataframe containing columns from both the caller and other.
See also
For column(s)-on-column(s) operations.
Notes
Parameters on, lsuffix, and rsuffix are not supported when passing a list of DataFrame objects.
Support for specifying index levels as the on parameter was added in version 0.23.0.
Examples
Join DataFrames using their indexes.
If we want to join using the key columns, we need to set key to be the index in both df and other. The joined DataFrame will have key as its index.
Another option to join using the key columns is to use the on parameter. DataFrame.join always uses other’s index but we can use any column in df. This method preserves the original DataFrame’s index in the result.
Using non-unique key values shows how they are matched.


Get the ‘info axis’ (see Indexing for more).
This is index for Series, columns for DataFrame.
Info axis.


Return unbiased kurtosis over requested axis.
Kurtosis obtained using Fisher’s definition of kurtosis (kurtosis of normal == 0.0). Normalized by N-1.
Axis for the function to be applied on.
Exclude NA/null values when computing the result.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
Additional keyword arguments to be passed to the function.


Select final periods of time series data based on a date offset.
For a DataFrame with a sorted DatetimeIndex, this function selects the last few rows based on a date offset.
The offset length of the data that will be selected. For instance, ‘3D’ will display all the rows having their index within the last 3 days.
A subset of the caller.
If the index is not a DatetimeIndex
See also
Select initial periods of time series based on a date offset.
Select values at a particular time of the day.
Select values between particular times of the day.
Examples
Get the rows for the last 3 days:
Notice the data for 3 last calendar days were returned, not the last 3 observed days in the dataset, and therefore data for 2018-04-11 was not returned.


Return index for last non-NA value or None, if no NA value is found.
Notes
If all elements are non-NA/null, returns None. Also returns None for empty Series/DataFrame.


Get Less than or equal to of dataframe and other, element-wise (binary operator le).
Among flexible wrappers (eq, ne, le, lt, ge, gt) to comparison operators.
Equivalent to ==, !=, <=, <, >=, > with support to choose axis (rows or columns) and level for comparison.
Any single or multiple element data structure, or list-like object.
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’).
Broadcast across a level, matching Index values on the passed MultiIndex level.
Result of the comparison.
See also
Compare DataFrames for equality elementwise.
Compare DataFrames for inequality elementwise.
Compare DataFrames for less than inequality or equality elementwise.
Compare DataFrames for strictly less than inequality elementwise.
Compare DataFrames for greater than inequality or equality elementwise.
Compare DataFrames for strictly greater than inequality elementwise.
Notes
Mismatched indices will be unioned together. NaN values are considered different (i.e. NaN != NaN).
Examples
Comparison with a scalar, using either the operator or method:
When other is a Series, the columns of a DataFrame are aligned with the index of other and broadcast:
Use the method to control the broadcast axis:
When comparing to an arbitrary sequence, the number of columns must match the number elements in other:
Use the method to control the axis:
Compare to a DataFrame of different shape.
Compare to a MultiIndex by level.


Access a group of rows and columns by label(s) or a boolean array.
.loc[] is primarily label based, but may also be used with a boolean array.
Allowed inputs are:
A single label, e.g. 5 or 'a', (note that 5 is interpreted as a label of the index, and never as an integer position along the index).
A list or array of labels, e.g. ['a', 'b', 'c'].
A slice object with labels, e.g. 'a':'f'.
Warning
Note that contrary to usual python slices, both the start and the stop are included
A boolean array of the same length as the axis being sliced, e.g. [True, False, True].
An alignable boolean Series. The index of the key will be aligned before masking.
An alignable Index. The Index of the returned selection will be the input.
A callable function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above)
See more at Selection by Label.
If any items are not found.
If an indexed key is passed and its index is unalignable to the frame index.
See also
Access a single value for a row/column label pair.
Access group of rows and columns by integer position(s).
Returns a cross-section (row(s) or column(s)) from the Series/DataFrame.
Access group of values using labels.
Examples
Getting values
Single label. Note this returns the row as a Series.
List of labels. Note using [[]] returns a DataFrame.
Single label for row and column
Slice with labels for row and single label for column. As mentioned above, note that both the start and stop of the slice are included.
Boolean list with the same length as the row axis
Alignable boolean Series:
Index (same behavior as df.reindex)
Conditional that returns a boolean Series
Conditional that returns a boolean Series with column labels specified
Callable that returns a boolean Series
Setting values
Set value for all items matching the list of labels
Set value for an entire row
Set value for an entire column
Set value for rows matching callable condition
Getting values on a DataFrame with an index that has integer labels
Another example using integers for the index
Slice with integer labels for rows. As mentioned above, note that both the start and stop of the slice are included.
Getting values with a MultiIndex
A number of examples using a DataFrame with a MultiIndex
Single label. Note this returns a DataFrame with a single index.
Single index tuple. Note this returns a Series.
Single label for row and column. Similar to passing in a tuple, this returns a Series.
Single tuple. Note using [[]] returns a DataFrame.
Single tuple for the index with a single label for the column
Slice from index tuple to single label
Slice from index tuple to index tuple


Label-based “fancy indexing” function for DataFrame. Given equal-length arrays of row and column labels, return an array of the values corresponding to each (row, col) pair.
Deprecated since version 1.2.0: DataFrame.lookup is deprecated, use DataFrame.melt and DataFrame.loc instead. For further details see Looking up values by index/column labels.
The row labels to use for lookup.
The column labels to use for lookup.
The found values.


Get Less than of dataframe and other, element-wise (binary operator lt).
Among flexible wrappers (eq, ne, le, lt, ge, gt) to comparison operators.
Equivalent to ==, !=, <=, <, >=, > with support to choose axis (rows or columns) and level for comparison.
Any single or multiple element data structure, or list-like object.
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’).
Broadcast across a level, matching Index values on the passed MultiIndex level.
Result of the comparison.
See also
Compare DataFrames for equality elementwise.
Compare DataFrames for inequality elementwise.
Compare DataFrames for less than inequality or equality elementwise.
Compare DataFrames for strictly less than inequality elementwise.
Compare DataFrames for greater than inequality or equality elementwise.
Compare DataFrames for strictly greater than inequality elementwise.
Notes
Mismatched indices will be unioned together. NaN values are considered different (i.e. NaN != NaN).
Examples
Comparison with a scalar, using either the operator or method:
When other is a Series, the columns of a DataFrame are aligned with the index of other and broadcast:
Use the method to control the broadcast axis:
When comparing to an arbitrary sequence, the number of columns must match the number elements in other:
Use the method to control the axis:
Compare to a DataFrame of different shape.
Compare to a MultiIndex by level.


Return the mean absolute deviation of the values over the requested axis.
Axis for the function to be applied on.
Exclude NA/null values when computing the result.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.


Replace values where the condition is True.
Where cond is False, keep the original value. Where True, replace with corresponding value from other. If cond is callable, it is computed on the Series/DataFrame and should return boolean Series/DataFrame or array. The callable must not change input Series/DataFrame (though pandas doesn’t check it).
Entries where cond is True are replaced with corresponding value from other. If other is callable, it is computed on the Series/DataFrame and should return scalar or Series/DataFrame. The callable must not change input Series/DataFrame (though pandas doesn’t check it).
Whether to perform the operation in place on the data.
Alignment axis if needed.
Alignment level if needed.
Note that currently this parameter won’t affect the results and will always coerce to a suitable dtype.
‘raise’ : allow exceptions to be raised.
‘ignore’ : suppress exceptions. On error return original object.
Try to cast the result back to the input type (if possible).
Deprecated since version 1.3.0: Manually cast back if necessary.
See also
Return an object of same shape as self.
Notes
The mask method is an application of the if-then idiom. For each element in the calling DataFrame, if cond is False the element is used; otherwise the corresponding element from the DataFrame other is used.
The signature for DataFrame.where() differs from numpy.where(). Roughly df1.where(m, df2) is equivalent to np.where(m, df1, df2).
For further details and examples see the mask documentation in indexing.
Examples


Return the maximum of the values over the requested axis.
If you want the index of the maximum, use idxmax. This is the equivalent of the numpy.ndarray method argmax.
Axis for the function to be applied on.
Exclude NA/null values when computing the result.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
Additional keyword arguments to be passed to the function.
See also
Return the sum.
Return the minimum.
Return the maximum.
Return the index of the minimum.
Return the index of the maximum.
Return the sum over the requested axis.
Return the minimum over the requested axis.
Return the maximum over the requested axis.
Return the index of the minimum over the requested axis.
Return the index of the maximum over the requested axis.
Examples


Return the mean of the values over the requested axis.
Axis for the function to be applied on.
Exclude NA/null values when computing the result.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
Additional keyword arguments to be passed to the function.


Return the median of the values over the requested axis.
Axis for the function to be applied on.
Exclude NA/null values when computing the result.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
Additional keyword arguments to be passed to the function.


Unpivot a DataFrame from wide to long format, optionally leaving identifiers set.
This function is useful to massage a DataFrame into a format where one or more columns are identifier variables (id_vars), while all other columns, considered measured variables (value_vars), are “unpivoted” to the row axis, leaving just two non-identifier columns, ‘variable’ and ‘value’.
Column(s) to use as identifier variables.
Column(s) to unpivot. If not specified, uses all columns that are not set as id_vars.
Name to use for the ‘variable’ column. If None it uses frame.columns.name or ‘variable’.
Name to use for the ‘value’ column.
If columns are a MultiIndex then use this level to melt.
If True, original index is ignored. If False, the original index is retained. Index labels will be repeated as necessary.
New in version 1.1.0.
Unpivoted DataFrame.
See also
Identical method.
Create a spreadsheet-style pivot table as a DataFrame.
Return reshaped DataFrame organized by given index / column values.
Explode a DataFrame from list-like columns to long format.
Examples
The names of ‘variable’ and ‘value’ columns can be customized:
Original index values can be kept around:
If you have multi-index columns:


Return the memory usage of each column in bytes.
The memory usage can optionally include the contribution of the index and elements of object dtype.
This value is displayed in DataFrame.info by default. This can be suppressed by setting pandas.options.display.memory_usage to False.
Specifies whether to include the memory usage of the DataFrame’s index in returned Series. If index=True, the memory usage of the index is the first item in the output.
If True, introspect the data deeply by interrogating object dtypes for system-level memory consumption, and include it in the returned values.
A Series whose index is the original column names and whose values is the memory usage of each column in bytes.
See also
Total bytes consumed by the elements of an ndarray.
Bytes consumed by a Series.
Memory-efficient array for string values with many repeated values.
Concise summary of a DataFrame.
Examples
The memory footprint of object dtype columns is ignored by default:
Use a Categorical for efficient storage of an object-dtype column with many repeated values.


Merge DataFrame or named Series objects with a database-style join.
A named Series object is treated as a DataFrame with a single named column.
The join is done on columns or indexes. If joining columns on columns, the DataFrame indexes will be ignored. Otherwise if joining indexes on indexes or indexes on a column or columns, the index will be passed on. When performing a cross merge, no column specifications to merge on are allowed.
Warning
If both key columns contain rows where the key is a null value, those rows will be matched against each other. This is different from usual SQL join behaviour and can lead to unexpected results.
Object to merge with.
Type of merge to be performed.
left: use only keys from left frame, similar to a SQL left outer join; preserve key order.
right: use only keys from right frame, similar to a SQL right outer join; preserve key order.
outer: use union of keys from both frames, similar to a SQL full outer join; sort keys lexicographically.
inner: use intersection of keys from both frames, similar to a SQL inner join; preserve the order of the left keys.
cross: creates the cartesian product from both frames, preserves the order of the left keys.
New in version 1.2.0.
Column or index level names to join on. These must be found in both DataFrames. If on is None and not merging on indexes then this defaults to the intersection of the columns in both DataFrames.
Column or index level names to join on in the left DataFrame. Can also be an array or list of arrays of the length of the left DataFrame. These arrays are treated as if they are columns.
Column or index level names to join on in the right DataFrame. Can also be an array or list of arrays of the length of the right DataFrame. These arrays are treated as if they are columns.
Use the index from the left DataFrame as the join key(s). If it is a MultiIndex, the number of keys in the other DataFrame (either the index or a number of columns) must match the number of levels.
Use the index from the right DataFrame as the join key. Same caveats as left_index.
Sort the join keys lexicographically in the result DataFrame. If False, the order of the join keys depends on the join type (how keyword).
A length-2 sequence where each element is optionally a string indicating the suffix to add to overlapping column names in left and right respectively. Pass a value of None instead of a string to indicate that the column name from left or right should be left as-is, with no suffix. At least one of the values must not be None.
If False, avoid copy if possible.
If True, adds a column to the output DataFrame called “_merge” with information on the source of each row. The column can be given a different name by providing a string argument. The column will have a Categorical type with the value of “left_only” for observations whose merge key only appears in the left DataFrame, “right_only” for observations whose merge key only appears in the right DataFrame, and “both” if the observation’s merge key is found in both DataFrames.
If specified, checks if merge is of specified type.
“one_to_one” or “1:1”: check if merge keys are unique in both left and right datasets.
“one_to_many” or “1:m”: check if merge keys are unique in left dataset.
“many_to_one” or “m:1”: check if merge keys are unique in right dataset.
“many_to_many” or “m:m”: allowed, but does not result in checks.
A DataFrame of the two merged objects.
See also
Merge with optional filling/interpolation.
Merge on nearest keys.
Similar method using indices.
Notes
Support for specifying index levels as the on, left_on, and right_on parameters was added in version 0.23.0 Support for merging named Series objects was added in version 0.24.0
Examples
Merge df1 and df2 on the lkey and rkey columns. The value columns have the default suffixes, _x and _y, appended.
Merge DataFrames df1 and df2 with specified left and right suffixes appended to any overlapping columns.
Merge DataFrames df1 and df2, but raise an exception if the DataFrames have any overlapping columns.


Return the minimum of the values over the requested axis.
If you want the index of the minimum, use idxmin. This is the equivalent of the numpy.ndarray method argmin.
Axis for the function to be applied on.
Exclude NA/null values when computing the result.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
Additional keyword arguments to be passed to the function.
See also
Return the sum.
Return the minimum.
Return the maximum.
Return the index of the minimum.
Return the index of the maximum.
Return the sum over the requested axis.
Return the minimum over the requested axis.
Return the maximum over the requested axis.
Return the index of the minimum over the requested axis.
Return the index of the maximum over the requested axis.
Examples


Get Modulo of dataframe and other, element-wise (binary operator mod).
Equivalent to dataframe % other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rmod.
Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.
Any single or multiple element data structure, or list-like object.
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’). For Series input, axis to match Series index on.
Broadcast across a level, matching Index values on the passed MultiIndex level.
Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing.
Result of the arithmetic operation.
See also
Add DataFrames.
Subtract DataFrames.
Multiply DataFrames.
Divide DataFrames (float division).
Divide DataFrames (float division).
Divide DataFrames (integer division).
Calculate modulo (remainder after division).
Calculate exponential power.
Notes
Mismatched indices will be unioned together.
Examples
Add a scalar with operator version which return the same results.
Divide by constant with reverse version.
Subtract a list and Series by axis with operator version.
Multiply a DataFrame of different shape with operator version.
Divide by a MultiIndex by level.


Get the mode(s) of each element along the selected axis.
The mode of a set of values is the value that appears most often. It can be multiple values.
The axis to iterate over while searching for the mode:
0 or ‘index’ : get mode of each column
1 or ‘columns’ : get mode of each row.
If True, only apply to numeric columns.
Don’t consider counts of NaN/NaT.
The modes of each column or row.
See also
Return the highest frequency value in a Series.
Return the counts of values in a Series.
Examples
By default, missing values are not considered, and the mode of wings are both 0 and 2. Because the resulting DataFrame has two rows, the second row of species and legs contains NaN.
Setting dropna=False NaN values are considered and they can be the mode (like for wings).
Setting numeric_only=True, only the mode of numeric columns is computed, and columns of other types are ignored.
To compute the mode over columns and not rows, use the axis parameter:


Get Multiplication of dataframe and other, element-wise (binary operator mul).
Equivalent to dataframe * other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rmul.
Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.
Any single or multiple element data structure, or list-like object.
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’). For Series input, axis to match Series index on.
Broadcast across a level, matching Index values on the passed MultiIndex level.
Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing.
Result of the arithmetic operation.
See also
Add DataFrames.
Subtract DataFrames.
Multiply DataFrames.
Divide DataFrames (float division).
Divide DataFrames (float division).
Divide DataFrames (integer division).
Calculate modulo (remainder after division).
Calculate exponential power.
Notes
Mismatched indices will be unioned together.
Examples
Add a scalar with operator version which return the same results.
Divide by constant with reverse version.
Subtract a list and Series by axis with operator version.
Multiply a DataFrame of different shape with operator version.
Divide by a MultiIndex by level.


Return an int representing the number of axes / array dimensions.
Return 1 if Series. Otherwise return 2 if DataFrame.
See also
Number of array dimensions.
Examples


Get Not equal to of dataframe and other, element-wise (binary operator ne).
Among flexible wrappers (eq, ne, le, lt, ge, gt) to comparison operators.
Equivalent to ==, !=, <=, <, >=, > with support to choose axis (rows or columns) and level for comparison.
Any single or multiple element data structure, or list-like object.
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’).
Broadcast across a level, matching Index values on the passed MultiIndex level.
Result of the comparison.
See also
Compare DataFrames for equality elementwise.
Compare DataFrames for inequality elementwise.
Compare DataFrames for less than inequality or equality elementwise.
Compare DataFrames for strictly less than inequality elementwise.
Compare DataFrames for greater than inequality or equality elementwise.
Compare DataFrames for strictly greater than inequality elementwise.
Notes
Mismatched indices will be unioned together. NaN values are considered different (i.e. NaN != NaN).
Examples
Comparison with a scalar, using either the operator or method:
When other is a Series, the columns of a DataFrame are aligned with the index of other and broadcast:
Use the method to control the broadcast axis:
When comparing to an arbitrary sequence, the number of columns must match the number elements in other:
Use the method to control the axis:
Compare to a DataFrame of different shape.
Compare to a MultiIndex by level.


Return the first n rows ordered by columns in descending order.
Return the first n rows with the largest values in columns, in descending order. The columns that are not specified are returned as well, but not used for ordering.
This method is equivalent to df.sort_values(columns, ascending=False).head(n), but more performant.
Number of rows to return.
Column label(s) to order by.
Where there are duplicate values:
first : prioritize the first occurrence(s)
last : prioritize the last occurrence(s)
all : do not drop any duplicates, even it means selecting more than n items.
The first n rows ordered by the given columns in descending order.
See also
Return the first n rows ordered by columns in ascending order.
Sort DataFrame by the values.
Return the first n rows without re-ordering.
Notes
This function cannot be used with all column types. For example, when specifying columns with object or category dtypes, TypeError is raised.
Examples
In the following example, we will use nlargest to select the three rows having the largest values in column “population”.
When using keep='last', ties are resolved in reverse order:
When using keep='all', all duplicate items are maintained:
To order by the largest values in column “population” and then “GDP”, we can specify multiple columns like in the next example.


Detect existing (non-missing) values.
Return a boolean same-sized object indicating if the values are not NA. Non-missing values get mapped to True. Characters such as empty strings '' or numpy.inf are not considered NA values (unless you set pandas.options.mode.use_inf_as_na = True). NA values, such as None or numpy.NaN, get mapped to False values.
Mask of bool values for each element in DataFrame that indicates whether an element is not an NA value.
See also
Alias of notna.
Boolean inverse of notna.
Omit axes labels with missing values.
Top-level notna.
Examples
Show which entries in a DataFrame are not NA.
Show which entries in a Series are not NA.


DataFrame.notnull is an alias for DataFrame.notna.
Detect existing (non-missing) values.
Return a boolean same-sized object indicating if the values are not NA. Non-missing values get mapped to True. Characters such as empty strings '' or numpy.inf are not considered NA values (unless you set pandas.options.mode.use_inf_as_na = True). NA values, such as None or numpy.NaN, get mapped to False values.
Mask of bool values for each element in DataFrame that indicates whether an element is not an NA value.
See also
Alias of notna.
Boolean inverse of notna.
Omit axes labels with missing values.
Top-level notna.
Examples
Show which entries in a DataFrame are not NA.
Show which entries in a Series are not NA.


Return the first n rows ordered by columns in ascending order.
Return the first n rows with the smallest values in columns, in ascending order. The columns that are not specified are returned as well, but not used for ordering.
This method is equivalent to df.sort_values(columns, ascending=True).head(n), but more performant.
Number of items to retrieve.
Column name or names to order by.
Where there are duplicate values:
first : take the first occurrence.
last : take the last occurrence.
all : do not drop any duplicates, even it means selecting more than n items.
See also
Return the first n rows ordered by columns in descending order.
Sort DataFrame by the values.
Return the first n rows without re-ordering.
Examples
In the following example, we will use nsmallest to select the three rows having the smallest values in column “population”.
When using keep='last', ties are resolved in reverse order:
When using keep='all', all duplicate items are maintained:
To order by the smallest values in column “population” and then “GDP”, we can specify multiple columns like in the next example.


Count number of distinct elements in specified axis.
Return Series with number of distinct elements. Can ignore NaN values.
The axis to use. 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise.
Don’t include NaN in the counts.
See also
Method nunique for Series.
Count non-NA cells for each column or row.
Examples


Synonym for DataFrame.fillna() with method='ffill'.
Object with missing values filled or None if inplace=True.


Percentage change between the current and a prior element.
Computes the percentage change from the immediately previous row by default. This is useful in comparing the percentage of change in a time series of elements.
Periods to shift for forming percent change.
How to handle NAs before computing percent changes.
The number of consecutive NAs to fill before stopping.
Increment to use from time series API (e.g. ‘M’ or BDay()).
Additional keyword arguments are passed into DataFrame.shift or Series.shift.
The same type as the calling object.
See also
Compute the difference of two elements in a Series.
Compute the difference of two elements in a DataFrame.
Shift the index by some number of periods.
Shift the index by some number of periods.
Examples
Series
See the percentage change in a Series where filling NAs with last valid observation forward to next valid.
DataFrame
Percentage change in French franc, Deutsche Mark, and Italian lira from 1980-01-01 to 1980-03-01.
Percentage of change in GOOG and APPL stock volume. Shows computing the percentage change between columns.


Apply chainable functions that expect Series or DataFrames.
Function to apply to the Series/DataFrame. args, and kwargs are passed into func. Alternatively a (callable, data_keyword) tuple where data_keyword is a string indicating the keyword of callable that expects the Series/DataFrame.
Positional arguments passed into func.
A dictionary of keyword arguments passed into func.
See also
Apply a function along input axis of DataFrame.
Apply a function elementwise on a whole DataFrame.
Apply a mapping correspondence on a Series.
Notes
Use .pipe when chaining together functions that expect Series, DataFrames or GroupBy objects. Instead of writing
You can write
If you have a function that takes the data as (say) the second argument, pass a tuple indicating which keyword expects the data. For example, suppose f takes its data as arg2:


Return reshaped DataFrame organized by given index / column values.
Reshape data (produce a “pivot” table) based on column values. Uses unique values from specified index / columns to form axes of the resulting DataFrame. This function does not support data aggregation, multiple values will result in a MultiIndex in the columns. See the User Guide for more on reshaping.
Column to use to make new frame’s index. If None, uses existing index.
Changed in version 1.1.0: Also accept list of index names.
Column to use to make new frame’s columns.
Changed in version 1.1.0: Also accept list of columns names.
Column(s) to use for populating new frame’s values. If not specified, all remaining columns will be used and the result will have hierarchically indexed columns.
Returns reshaped DataFrame.
When there are any index, columns combinations with multiple values. DataFrame.pivot_table when you need to aggregate.
See also
Generalization of pivot that can handle duplicate values for one index/column pair.
Pivot based on the index values instead of a column.
Wide panel to long format. Less flexible but more user-friendly than melt.
Notes
For finer-tuned control, see hierarchical indexing documentation along with the related stack/unstack methods.
Examples
You could also assign a list of column names or a list of index names.
A ValueError is raised if there are any duplicates.
Notice that the first two rows are the same for our index and columns arguments.


Create a spreadsheet-style pivot table as a DataFrame.
The levels in the pivot table will be stored in MultiIndex objects (hierarchical indexes) on the index and columns of the result DataFrame.
If an array is passed, it must be the same length as the data. The list can contain any of the other types (except list). Keys to group by on the pivot table index. If an array is passed, it is being used as the same manner as column values.
If an array is passed, it must be the same length as the data. The list can contain any of the other types (except list). Keys to group by on the pivot table column. If an array is passed, it is being used as the same manner as column values.
If list of functions passed, the resulting pivot table will have hierarchical columns whose top level are the function names (inferred from the function objects themselves) If dict is passed, the key is column to aggregate and value is function or list of functions.
Value to replace missing values with (in the resulting pivot table, after aggregation).
Add all row / columns (e.g. for subtotal / grand totals).
Do not include columns whose entries are all NaN.
Name of the row / column that will contain the totals when margins is True.
This only applies if any of the groupers are Categoricals. If True: only show observed values for categorical groupers. If False: show all values for categorical groupers.
Changed in version 0.25.0.
Specifies if the result should be sorted.
New in version 1.3.0.
An Excel style pivot table.
See also
Pivot without aggregation that can handle non-numeric data.
Unpivot a DataFrame from wide to long format, optionally leaving identifiers set.
Wide panel to long format. Less flexible but more user-friendly than melt.
Examples
This first example aggregates values by taking the sum.
We can also fill missing values using the fill_value parameter.
The next example aggregates by taking the mean across multiple columns.
We can also calculate multiple types of aggregations for any given value column.


Make plots of Series or DataFrame.
Uses the backend specified by the option plotting.backend. By default, matplotlib is used.
The object for which the method is called.
Only used if data is a DataFrame.
Allows plotting of one column versus another. Only used if data is a DataFrame.
The kind of plot to produce:
‘line’ : line plot (default)
‘bar’ : vertical bar plot
‘barh’ : horizontal bar plot
‘hist’ : histogram
‘box’ : boxplot
‘kde’ : Kernel Density Estimation plot
‘density’ : same as ‘kde’
‘area’ : area plot
‘pie’ : pie plot
‘scatter’ : scatter plot (DataFrame only)
‘hexbin’ : hexbin plot (DataFrame only)
An axes of the current figure.
Make separate subplots for each column.
In case subplots=True, share x axis and set some x axis labels to invisible; defaults to True if ax is None otherwise False if an ax is passed in; Be aware, that passing in both an ax and sharex=True will alter all x axis labels for all axis in a figure.
In case subplots=True, share y axis and set some y axis labels to invisible.
(rows, columns) for the layout of subplots.
Size of a figure object.
Use index as ticks for x axis.
Title to use for the plot. If a string is passed, print the string at the top of the figure. If a list is passed and subplots is True, print each item in the list above the corresponding subplot.
Axis grid lines.
Place legend on axis subplots.
The matplotlib line style per column.
Use log scaling or symlog scaling on x axis. .. versionchanged:: 0.25.0
Use log scaling or symlog scaling on y axis. .. versionchanged:: 0.25.0
Use log scaling or symlog scaling on both x and y axes. .. versionchanged:: 0.25.0
Values to use for the xticks.
Values to use for the yticks.
Set the x limits of the current axes.
Set the y limits of the current axes.
Name to use for the xlabel on x-axis. Default uses index name as xlabel, or the x-column name for planar plots.
New in version 1.1.0.
Changed in version 1.2.0: Now applicable to planar plots (scatter, hexbin).
Name to use for the ylabel on y-axis. Default will show no ylabel, or the y-column name for planar plots.
New in version 1.1.0.
Changed in version 1.2.0: Now applicable to planar plots (scatter, hexbin).
Rotation for ticks (xticks for vertical, yticks for horizontal plots).
Font size for xticks and yticks.
Colormap to select colors from. If string, load colormap with that name from matplotlib.
If True, plot colorbar (only relevant for ‘scatter’ and ‘hexbin’ plots).
Specify relative alignments for bar plot layout. From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5 (center).
If True, draw a table using the data in the DataFrame and the data will be transposed to meet matplotlib’s default layout. If a Series or DataFrame is passed, use passed data to draw a table.
See Plotting with Error Bars for detail.
Equivalent to yerr.
If True, create stacked plot.
Sort column names to determine plot ordering.
Whether to plot on the secondary y-axis if a list/tuple, which columns to plot on secondary y-axis.
When using a secondary_y axis, automatically mark the column labels with “(right)” in the legend.
If True, boolean values can be plotted.
Backend to use instead of the backend specified in the option plotting.backend. For instance, ‘matplotlib’. Alternatively, to specify the plotting.backend for the whole session, set pd.options.plotting.backend.
New in version 1.0.0.
Options to pass to matplotlib plotting method.
If the backend is not the default matplotlib one, the return value will be the object returned by the backend.
Notes
See matplotlib documentation online for more on this subject
If kind = ‘bar’ or ‘barh’, you can specify relative alignments for bar plot layout by position keyword. From 0 (left/bottom-end) to 1 (right/top-end). Default is 0.5 (center)


Draw a stacked area plot.
An area plot displays quantitative data visually. This function wraps the matplotlib area function.
Coordinates for the X axis. By default uses the index.
Column to plot. By default uses all columns.
Area plots are stacked by default. Set to False to create a unstacked plot.
Additional keyword arguments are documented in DataFrame.plot().
Area plot, or array of area plots if subplots is True.
See also
Make plots of DataFrame using matplotlib / pylab.
Examples
Draw an area plot based on basic business metrics:
Area plots are stacked by default. To produce an unstacked plot, pass stacked=False:
Draw an area plot for a single column:
Draw with a different x:


Vertical bar plot.
A bar plot is a plot that presents categorical data with rectangular bars with lengths proportional to the values that they represent. A bar plot shows comparisons among discrete categories. One axis of the plot shows the specific categories being compared, and the other axis represents a measured value.
Allows plotting of one column versus another. If not specified, the index of the DataFrame is used.
Allows plotting of one column versus another. If not specified, all numerical columns are used.
The color for each of the DataFrame’s columns. Possible values are:
for instance ‘red’ or ‘#a98d19’.
code, which will be used for each column recursively. For instance [‘green’,’yellow’] each column’s bar will be filled in green or yellow, alternatively. If there is only a single column to be plotted, then only the first color from the color list will be used.
colored accordingly. For example, if your columns are called a and b, then passing {‘a’: ‘green’, ‘b’: ‘red’} will color bars for column a in green and bars for column b in red.
New in version 1.1.0.
Additional keyword arguments are documented in DataFrame.plot().
An ndarray is returned with one matplotlib.axes.Axes per column when subplots=True.
See also
Horizontal bar plot.
Make plots of a DataFrame.
Make a bar plot with matplotlib.
Examples
Basic plot.
Plot a whole dataframe to a bar plot. Each column is assigned a distinct color, and each row is nested in a group along the horizontal axis.
Plot stacked bar charts for the DataFrame
Instead of nesting, the figure can be split by column with subplots=True. In this case, a numpy.ndarray of matplotlib.axes.Axes are returned.
If you don’t like the default colours, you can specify how you’d like each column to be colored.
Plot a single column.
Plot only selected categories for the DataFrame.


Make a horizontal bar plot.
A horizontal bar plot is a plot that presents quantitative data with rectangular bars with lengths proportional to the values that they represent. A bar plot shows comparisons among discrete categories. One axis of the plot shows the specific categories being compared, and the other axis represents a measured value.
Allows plotting of one column versus another. If not specified, the index of the DataFrame is used.
Allows plotting of one column versus another. If not specified, all numerical columns are used.
The color for each of the DataFrame’s columns. Possible values are:
for instance ‘red’ or ‘#a98d19’.
code, which will be used for each column recursively. For instance [‘green’,’yellow’] each column’s bar will be filled in green or yellow, alternatively. If there is only a single column to be plotted, then only the first color from the color list will be used.
colored accordingly. For example, if your columns are called a and b, then passing {‘a’: ‘green’, ‘b’: ‘red’} will color bars for column a in green and bars for column b in red.
New in version 1.1.0.
Additional keyword arguments are documented in DataFrame.plot().
An ndarray is returned with one matplotlib.axes.Axes per column when subplots=True.
See also
Vertical bar plot.
Make plots of DataFrame using matplotlib.
Plot a vertical bar plot using matplotlib.
Examples
Basic example
Plot a whole DataFrame to a horizontal bar plot
Plot stacked barh charts for the DataFrame
We can specify colors for each column
Plot a column of the DataFrame to a horizontal bar plot
Plot DataFrame versus the desired column


Make a box plot of the DataFrame columns.
A box plot is a method for graphically depicting groups of numerical data through their quartiles. The box extends from the Q1 to Q3 quartile values of the data, with a line at the median (Q2). The whiskers extend from the edges of box to show the range of the data. The position of the whiskers is set by default to 1.5*IQR (IQR = Q3 - Q1) from the edges of the box. Outlier points are those past the end of the whiskers.
For further details see Wikipedia’s entry for boxplot.
A consideration when using this chart is that the box and the whiskers can overlap, which is very common when plotting small sets of data.
Column in the DataFrame to group by.
Changed in version 1.4.0: Previously, by is silently ignore and makes no groupings
Additional keywords are documented in DataFrame.plot().
See also
Another method to draw a box plot.
Draw a box plot from a Series object.
Draw a box plot in matplotlib.
Examples
Draw a box plot from a DataFrame with four columns of randomly generated data.
You can also generate groupings if you specify the by parameter (which can take a column name, or a list or tuple of column names):
Changed in version 1.4.0.


Generate Kernel Density Estimate plot using Gaussian kernels.
In statistics, kernel density estimation (KDE) is a non-parametric way to estimate the probability density function (PDF) of a random variable. This function uses Gaussian kernels and includes automatic bandwidth determination.
The method used to calculate the estimator bandwidth. This can be ‘scott’, ‘silverman’, a scalar constant or a callable. If None (default), ‘scott’ is used. See scipy.stats.gaussian_kde for more information.
Evaluation points for the estimated PDF. If None (default), 1000 equally spaced points are used. If ind is a NumPy array, the KDE is evaluated at the points passed. If ind is an integer, ind number of equally spaced points are used.
Additional keyword arguments are documented in pandas.%(this-datatype)s.plot().
See also
Representation of a kernel-density estimate using Gaussian kernels. This is the function used internally to estimate the PDF.
Examples
Given a Series of points randomly sampled from an unknown distribution, estimate its PDF using KDE with automatic bandwidth determination and plot the results, evaluating them at 1000 equally spaced points (default):
A scalar bandwidth can be specified. Using a small bandwidth value can lead to over-fitting, while using a large bandwidth value may result in under-fitting:
Finally, the ind parameter determines the evaluation points for the plot of the estimated PDF:
For DataFrame, it works in the same way:
A scalar bandwidth can be specified. Using a small bandwidth value can lead to over-fitting, while using a large bandwidth value may result in under-fitting:
Finally, the ind parameter determines the evaluation points for the plot of the estimated PDF:


Generate a hexagonal binning plot.
Generate a hexagonal binning plot of x versus y. If C is None (the default), this is a histogram of the number of occurrences of the observations at (x[i], y[i]).
If C is specified, specifies values at given coordinates (x[i], y[i]). These values are accumulated for each hexagonal bin and then reduced according to reduce_C_function, having as default the NumPy’s mean function (numpy.mean()). (If C is specified, it must also be a 1-D sequence of the same length as x and y, or a column label.)
The column label or position for x points.
The column label or position for y points.
The column label or position for the value of (x, y) point.
Function of one argument that reduces all the values in a bin to a single number (e.g. np.mean, np.max, np.sum, np.std).
The number of hexagons in the x-direction. The corresponding number of hexagons in the y-direction is chosen in a way that the hexagons are approximately regular. Alternatively, gridsize can be a tuple with two elements specifying the number of hexagons in the x-direction and the y-direction.
Additional keyword arguments are documented in DataFrame.plot().
The matplotlib Axes on which the hexbin is plotted.
See also
Make plots of a DataFrame.
Hexagonal binning plot using matplotlib, the matplotlib function that is used under the hood.
Examples
The following examples are generated with random data from a normal distribution.
The next example uses C and np.sum as reduce_C_function. Note that ‘observations’ values ranges from 1 to 5 but the result plot shows values up to more than 25. This is because of the reduce_C_function.


Draw one histogram of the DataFrame’s columns.
A histogram is a representation of the distribution of data. This function groups the values of all given Series in the DataFrame into bins and draws all bins in one matplotlib.axes.Axes. This is useful when the DataFrame’s Series are in a similar scale.
Column in the DataFrame to group by.
Changed in version 1.4.0: Previously, by is silently ignore and makes no groupings
Number of histogram bins to be used.
Additional keyword arguments are documented in DataFrame.plot().
Return a histogram plot.
See also
Draw histograms per DataFrame’s Series.
Draw a histogram with Series’ data.
Examples
When we roll a die 6000 times, we expect to get each value around 1000 times. But when we roll two dice and sum the result, the distribution is going to be quite different. A histogram illustrates those distributions.
A grouped histogram can be generated by providing the parameter by (which can be a column name, or a list of column names):


Plot Series or DataFrame as lines.
This function is useful to plot lines using DataFrame’s values as coordinates.
Allows plotting of one column versus another. If not specified, the index of the DataFrame is used.
Allows plotting of one column versus another. If not specified, all numerical columns are used.
The color for each of the DataFrame’s columns. Possible values are:
for instance ‘red’ or ‘#a98d19’.
code, which will be used for each column recursively. For instance [‘green’,’yellow’] each column’s line will be filled in green or yellow, alternatively. If there is only a single column to be plotted, then only the first color from the color list will be used.
colored accordingly. For example, if your columns are called a and b, then passing {‘a’: ‘green’, ‘b’: ‘red’} will color lines for column a in green and lines for column b in red.
New in version 1.1.0.
Additional keyword arguments are documented in DataFrame.plot().
An ndarray is returned with one matplotlib.axes.Axes per column when subplots=True.
See also
Plot y versus x as lines and/or markers.
Examples
The following example shows the populations for some animals over the years.
An example with subplots, so an array of axes is returned.
Let’s repeat the same example, but specifying colors for each column (in this case, for each animal).
The following example shows the relationship between both populations.


Generate a pie plot.
A pie plot is a proportional representation of the numerical data in a column. This function wraps matplotlib.pyplot.pie() for the specified column. If no column reference is passed and subplots=True a pie plot is drawn for each numerical column independently.
Label or position of the column to plot. If not provided, subplots=True argument must be passed.
Keyword arguments to pass on to DataFrame.plot().
A NumPy array is returned when subplots is True.
See also
Generate a pie plot for a Series.
Make plots of a DataFrame.
Examples
In the example below we have a DataFrame with the information about planet’s mass and radius. We pass the ‘mass’ column to the pie function to get a pie plot.


Create a scatter plot with varying marker point size and color.
The coordinates of each point are defined by two dataframe columns and filled circles are used to represent each point. This kind of plot is useful to see complex correlations between two variables. Points could be for instance natural 2D coordinates like longitude and latitude in a map or, in general, any pair of metrics that can be plotted against each other.
The column name or column position to be used as horizontal coordinates for each point.
The column name or column position to be used as vertical coordinates for each point.
The size of each point. Possible values are:
A string with the name of the column to be used for marker’s size.
A single scalar so all points have the same size.
A sequence of scalars, which will be used for each point’s size recursively. For instance, when passing [2,14] all points size will be either 2 or 14, alternatively.
Changed in version 1.1.0.
The color of each point. Possible values are:
A single color string referred to by name, RGB or RGBA code, for instance ‘red’ or ‘#a98d19’.
A sequence of color strings referred to by name, RGB or RGBA code, which will be used for each point’s color recursively. For instance [‘green’,’yellow’] all points will be filled in green or yellow, alternatively.
A column name or position whose values will be used to color the marker points according to a colormap.
Keyword arguments to pass on to DataFrame.plot().
See also
Scatter plot using multiple input data formats.
Examples
Let’s see how to draw a scatter plot using coordinates from the values in a DataFrame’s columns.
And now with the color determined by a column as well.


Return item and drop from frame. Raise KeyError if not found.
Label of column to be popped.
Examples


Get Exponential power of dataframe and other, element-wise (binary operator pow).
Equivalent to dataframe ** other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rpow.
Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.
Any single or multiple element data structure, or list-like object.
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’). For Series input, axis to match Series index on.
Broadcast across a level, matching Index values on the passed MultiIndex level.
Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing.
Result of the arithmetic operation.
See also
Add DataFrames.
Subtract DataFrames.
Multiply DataFrames.
Divide DataFrames (float division).
Divide DataFrames (float division).
Divide DataFrames (integer division).
Calculate modulo (remainder after division).
Calculate exponential power.
Notes
Mismatched indices will be unioned together.
Examples
Add a scalar with operator version which return the same results.
Divide by constant with reverse version.
Subtract a list and Series by axis with operator version.
Multiply a DataFrame of different shape with operator version.
Divide by a MultiIndex by level.


Return the product of the values over the requested axis.
Axis for the function to be applied on.
Exclude NA/null values when computing the result.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
The required number of valid values to perform the operation. If fewer than min_count non-NA values are present the result will be NA.
Additional keyword arguments to be passed to the function.
See also
Return the sum.
Return the minimum.
Return the maximum.
Return the index of the minimum.
Return the index of the maximum.
Return the sum over the requested axis.
Return the minimum over the requested axis.
Return the maximum over the requested axis.
Return the index of the minimum over the requested axis.
Return the index of the maximum over the requested axis.
Examples
By default, the product of an empty or all-NA Series is 1
This can be controlled with the min_count parameter
Thanks to the skipna parameter, min_count handles all-NA and empty series identically.


Return values at the given quantile over requested axis.
Value between 0 <= q <= 1, the quantile(s) to compute.
Equals 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise.
If False, the quantile of datetime and timedelta data will be computed as well.
This optional parameter specifies the interpolation method to use, when the desired quantile lies between two data points i and j:
linear: i + (j - i) * fraction, where fraction is the fractional part of the index surrounded by i and j.
lower: i.
higher: j.
nearest: i or j whichever is nearest.
midpoint: (i + j) / 2.
index is q, the columns are the columns of self, and the values are the quantiles.
index is the columns of self and the values are the quantiles.
See also
Rolling quantile.
Numpy function to compute the percentile.
Examples
Specifying numeric_only=False will also compute the quantile of datetime and timedelta data.


Query the columns of a DataFrame with a boolean expression.
The query string to evaluate.
You can refer to variables in the environment by prefixing them with an ‘@’ character like @a + b.
You can refer to column names that are not valid Python variable names by surrounding them in backticks. Thus, column names containing spaces or punctuations (besides underscores) or starting with digits must be surrounded by backticks. (For example, a column named “Area (cm^2)” would be referenced as `Area (cm^2)`). Column names which are Python keywords (like “list”, “for”, “import”, etc) cannot be used.
For example, if one of your columns is called a a and you want to sum it with b, your query should be `a a` + b.
New in version 0.25.0: Backtick quoting introduced.
New in version 1.0.0: Expanding functionality of backtick quoting for more than only spaces.
Whether the query should modify the data in place or return a modified copy.
See the documentation for eval() for complete details on the keyword arguments accepted by DataFrame.query().
DataFrame resulting from the provided query expression or None if inplace=True.
See also
Evaluate a string describing operations on DataFrame columns.
Evaluate a string describing operations on DataFrame columns.
Notes
The result of the evaluation of this expression is first passed to DataFrame.loc and if that fails because of a multidimensional key (e.g., a DataFrame) then the result will be passed to DataFrame.__getitem__().
This method uses the top-level eval() function to evaluate the passed query.
The query() method uses a slightly modified Python syntax by default. For example, the & and | (bitwise) operators have the precedence of their boolean cousins, and and or. This is syntactically valid Python, however the semantics are different.
You can change the semantics of the expression by passing the keyword argument parser='python'. This enforces the same semantics as evaluation in Python space. Likewise, you can pass engine='python' to evaluate an expression using Python itself as a backend. This is not recommended as it is inefficient compared to using numexpr as the engine.
The DataFrame.index and DataFrame.columns attributes of the DataFrame instance are placed in the query namespace by default, which allows you to treat both the index and columns of the frame as a column in the frame. The identifier index is used for the frame index; you can also use the name of the index to identify it in a query. Please note that Python keywords may not be used as identifiers.
For further details and examples see the query documentation in indexing.
Backtick quoted variables
Backtick quoted variables are parsed as literal Python code and are converted internally to a Python valid identifier. This can lead to the following problems.
During parsing a number of disallowed characters inside the backtick quoted string are replaced by strings that are allowed as a Python identifier. These characters include all operators in Python, the space character, the question mark, the exclamation mark, the dollar sign, and the euro sign. For other characters that fall outside the ASCII range (U+0001..U+007F) and those that are not further specified in PEP 3131, the query parser will raise an error. This excludes whitespace different than the space character, but also the hashtag (as it is used for comments) and the backtick itself (backtick can also not be escaped).
In a special case, quotes that make a pair around a backtick can confuse the parser. For example, `it's` > `that's` will raise an error, as it forms a quoted string ('s > `that') with a backtick inside.
See also the Python documentation about lexical analysis (https://docs.python.org/3/reference/lexical_analysis.html) in combination with the source code in pandas.core.computation.parsing.
Examples
The previous expression is equivalent to
For columns with spaces in their name, you can use backtick quoting.
The previous expression is equivalent to


Get Addition of dataframe and other, element-wise (binary operator radd).
Equivalent to other + dataframe, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, add.
Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.
Any single or multiple element data structure, or list-like object.
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’). For Series input, axis to match Series index on.
Broadcast across a level, matching Index values on the passed MultiIndex level.
Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing.
Result of the arithmetic operation.
See also
Add DataFrames.
Subtract DataFrames.
Multiply DataFrames.
Divide DataFrames (float division).
Divide DataFrames (float division).
Divide DataFrames (integer division).
Calculate modulo (remainder after division).
Calculate exponential power.
Notes
Mismatched indices will be unioned together.
Examples
Add a scalar with operator version which return the same results.
Divide by constant with reverse version.
Subtract a list and Series by axis with operator version.
Multiply a DataFrame of different shape with operator version.
Divide by a MultiIndex by level.


Compute numerical data ranks (1 through n) along axis.
By default, equal values are assigned a rank that is the average of the ranks of those values.
Index to direct ranking.
How to rank the group of records that have the same value (i.e. ties):
average: average rank of the group
min: lowest rank in the group
max: highest rank in the group
first: ranks assigned in order they appear in the array
dense: like ‘min’, but rank always increases by 1 between groups.
For DataFrame objects, rank only numeric columns if set to True.
How to rank NaN values:
keep: assign NaN rank to NaN values
top: assign lowest rank to NaN values
bottom: assign highest rank to NaN values
Whether or not the elements should be ranked in ascending order.
Whether or not to display the returned rankings in percentile form.
Return a Series or DataFrame with data ranks as values.
See also
Rank of values within each group.
Examples
The following example shows how the method behaves with the above parameters:
default_rank: this is the default behaviour obtained without using any parameter.
max_rank: setting method = 'max' the records that have the same values are ranked using the highest rank (e.g.: since ‘cat’ and ‘dog’ are both in the 2nd and 3rd position, rank 3 is assigned.)
NA_bottom: choosing na_option = 'bottom', if there are records with NaN values they are placed at the bottom of the ranking.
pct_rank: when setting pct = True, the ranking is expressed as percentile rank.


Get Floating division of dataframe and other, element-wise (binary operator rtruediv).
Equivalent to other / dataframe, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, truediv.
Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.
Any single or multiple element data structure, or list-like object.
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’). For Series input, axis to match Series index on.
Broadcast across a level, matching Index values on the passed MultiIndex level.
Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing.
Result of the arithmetic operation.
See also
Add DataFrames.
Subtract DataFrames.
Multiply DataFrames.
Divide DataFrames (float division).
Divide DataFrames (float division).
Divide DataFrames (integer division).
Calculate modulo (remainder after division).
Calculate exponential power.
Notes
Mismatched indices will be unioned together.
Examples
Add a scalar with operator version which return the same results.
Divide by constant with reverse version.
Subtract a list and Series by axis with operator version.
Multiply a DataFrame of different shape with operator version.
Divide by a MultiIndex by level.


Conform Series/DataFrame to new index with optional filling logic.
Places NA/NaN in locations having no value in the previous index. A new object is produced unless the new index is equivalent to the current one and copy=False.
New labels / index to conform to, should be specified using keywords. Preferably an Index object to avoid duplicating data.
Method to use for filling holes in reindexed DataFrame. Please note: this is only applicable to DataFrames/Series with a monotonically increasing/decreasing index.
None (default): don’t fill gaps
pad / ffill: Propagate last valid observation forward to next valid.
backfill / bfill: Use next valid observation to fill gap.
nearest: Use nearest valid observations to fill gap.
Return a new object, even if the passed indexes are the same.
Broadcast across a level, matching Index values on the passed MultiIndex level.
Value to use for missing values. Defaults to NaN, but can be any “compatible” value.
Maximum number of consecutive elements to forward or backward fill.
Maximum distance between original and new labels for inexact matches. The values of the index at the matching locations most satisfy the equation abs(index[indexer] - target) <= tolerance.
Tolerance may be a scalar value, which applies the same tolerance to all values, or list-like, which applies variable tolerance per element. List-like includes list, tuple, array, Series, and must be the same size as the index and its dtype must exactly match the index’s type.
See also
Set row labels.
Remove row labels or move them to new columns.
Change to same indices as other DataFrame.
Examples
DataFrame.reindex supports two calling conventions
(index=index_labels, columns=column_labels, ...)
(labels, axis={'index', 'columns'}, ...)
We highly recommend using keyword arguments to clarify your intent.
Create a dataframe with some fictional data.
Create a new index and reindex the dataframe. By default values in the new index that do not have corresponding records in the dataframe are assigned NaN.
We can fill in the missing values by passing a value to the keyword fill_value. Because the index is not monotonically increasing or decreasing, we cannot use arguments to the keyword method to fill the NaN values.
We can also reindex the columns.
Or we can use “axis-style” keyword arguments
To further illustrate the filling functionality in reindex, we will create a dataframe with a monotonically increasing index (for example, a sequence of dates).
Suppose we decide to expand the dataframe to cover a wider date range.
The index entries that did not have a value in the original data frame (for example, ‘2009-12-29’) are by default filled with NaN. If desired, we can fill in the missing values using one of several options.
For example, to back-propagate the last valid value to fill the NaN values, pass bfill as an argument to the method keyword.
Please note that the NaN value present in the original dataframe (at index value 2010-01-03) will not be filled by any of the value propagation schemes. This is because filling while reindexing does not look at dataframe values, but only compares the original and desired indexes. If you do want to fill in the NaN values present in the original dataframe, use the fillna() method.
See the user guide for more.


Return an object with matching indices as other object.
Conform the object to the same index on all axes. Optional filling logic, placing NaN in locations having no value in the previous index. A new object is produced unless the new index is equivalent to the current one and copy=False.
Its row and column indices are used to define the new indices of this object.
Method to use for filling holes in reindexed DataFrame. Please note: this is only applicable to DataFrames/Series with a monotonically increasing/decreasing index.
None (default): don’t fill gaps
pad / ffill: propagate last valid observation forward to next valid
backfill / bfill: use next valid observation to fill gap
nearest: use nearest valid observations to fill gap.
Return a new object, even if the passed indexes are the same.
Maximum number of consecutive labels to fill for inexact matches.
Maximum distance between original and new labels for inexact matches. The values of the index at the matching locations must satisfy the equation abs(index[indexer] - target) <= tolerance.
Tolerance may be a scalar value, which applies the same tolerance to all values, or list-like, which applies variable tolerance per element. List-like includes list, tuple, array, Series, and must be the same size as the index and its dtype must exactly match the index’s type.
Same type as caller, but with changed indices on each axis.
See also
Set row labels.
Remove row labels or move them to new columns.
Change to new indices or expand indices.
Notes
Same as calling .reindex(index=other.index, columns=other.columns,...).
Examples


Alter axes labels.
Function / dict values must be unique (1-to-1). Labels not contained in a dict / Series will be left as-is. Extra labels listed don’t throw an error.
See the user guide for more.
Dict-like or function transformations to apply to that axis’ values. Use either mapper and axis to specify the axis to target with mapper, or index and columns.
Alternative to specifying axis (mapper, axis=0 is equivalent to index=mapper).
Alternative to specifying axis (mapper, axis=1 is equivalent to columns=mapper).
Axis to target with mapper. Can be either the axis name (‘index’, ‘columns’) or number (0, 1). The default is ‘index’.
Also copy underlying data.
Whether to return a new DataFrame. If True then value of copy is ignored.
In case of a MultiIndex, only rename labels in the specified level.
If ‘raise’, raise a KeyError when a dict-like mapper, index, or columns contains labels that are not present in the Index being transformed. If ‘ignore’, existing keys will be renamed and extra keys will be ignored.
DataFrame with the renamed axis labels or None if inplace=True.
If any of the labels is not found in the selected axis and “errors=’raise’”.
See also
Set the name of the axis.
Examples
DataFrame.rename supports two calling conventions
(index=index_mapper, columns=columns_mapper, ...)
(mapper, axis={'index', 'columns'}, ...)
We highly recommend using keyword arguments to clarify your intent.
Rename columns using a mapping:
Rename index using a mapping:
Cast index labels to a different type:
Using axis-style parameters:


Set the name of the axis for the index or columns.
Value to set the axis name attribute.
A scalar, list-like, dict-like or functions transformations to apply to that axis’ values. Note that the columns parameter is not allowed if the object is a Series. This parameter only apply for DataFrame type objects.
Use either mapper and axis to specify the axis to target with mapper, or index and/or columns.
The axis to rename.
Also copy underlying data.
Modifies the object directly, instead of creating a new Series or DataFrame.
The same type as the caller or None if inplace=True.
See also
Alter Series index labels or name.
Alter DataFrame index labels or name.
Set new names on index.
Notes
DataFrame.rename_axis supports two calling conventions
(index=index_mapper, columns=columns_mapper, ...)
(mapper, axis={'index', 'columns'}, ...)
The first calling convention will only modify the names of the index and/or the names of the Index object that is the columns. In this case, the parameter copy is ignored.
The second calling convention will modify the names of the corresponding index if mapper is a list or a scalar. However, if mapper is dict-like or a function, it will use the deprecated behavior of modifying the axis labels.
We highly recommend using keyword arguments to clarify your intent.
Examples
Series
DataFrame
MultiIndex


Rearrange index levels using input order. May not drop or duplicate levels.
List representing new level order. Reference level by number (position) or by key (label).
Where to reorder levels.
Examples
Let’s reorder the levels of the index:


Replace values given in to_replace with value.
Values of the DataFrame are replaced with other values dynamically.
This differs from updating with .loc or .iloc, which require you to specify a location to update with some value.
How to find the values that will be replaced.
numeric, str or regex:
numeric: numeric values equal to to_replace will be replaced with value
str: string exactly matching to_replace will be replaced with value
regex: regexs matching to_replace will be replaced with value
list of str, regex, or numeric:
First, if to_replace and value are both lists, they must be the same length.
Second, if regex=True then all of the strings in both lists will be interpreted as regexs otherwise they will match directly. This doesn’t matter much for value since there are only a few possible substitution regexes you can use.
str, regex and numeric rules apply as above.
dict:
Dicts can be used to specify different replacement values for different existing values. For example, {'a': 'b', 'y': 'z'} replaces the value ‘a’ with ‘b’ and ‘y’ with ‘z’. To use a dict in this way the value parameter should be None.
For a DataFrame a dict can specify that different values should be replaced in different columns. For example, {'a': 1, 'b': 'z'} looks for the value 1 in column ‘a’ and the value ‘z’ in column ‘b’ and replaces these values with whatever is specified in value. The value parameter should not be None in this case. You can treat this as a special case of passing two lists except that you are specifying the column to search in.
For a DataFrame nested dictionaries, e.g., {'a': {'b': np.nan}}, are read as follows: look in column ‘a’ for the value ‘b’ and replace it with NaN. The value parameter should be None to use a nested dict in this way. You can nest regular expressions as well. Note that column names (the top-level dictionary keys in a nested dictionary) cannot be regular expressions.
None:
This means that the regex argument must be a string, compiled regular expression, or list, dict, ndarray or Series of such elements. If value is also None then this must be a nested dictionary or Series.
See the examples section for examples of each of these.
Value to replace any values matching to_replace with. For a DataFrame a dict of values can be used to specify which value to use for each column (columns not in the dict will not be filled). Regular expressions, strings and lists or dicts of such objects are also allowed.
If True, performs operation inplace and returns None.
Maximum size gap to forward or backward fill.
Whether to interpret to_replace and/or value as regular expressions. If this is True then to_replace must be a string. Alternatively, this could be a regular expression or a list, dict, or array of regular expressions in which case to_replace must be None.
The method to use when for replacement, when to_replace is a scalar, list or tuple and value is None.
Changed in version 0.23.0: Added to DataFrame.
Object after replacement.
If regex is not a bool and to_replace is not None.
If to_replace is not a scalar, array-like, dict, or None
If to_replace is a dict and value is not a list, dict, ndarray, or Series
If to_replace is None and regex is not compilable into a regular expression or is a list, dict, ndarray, or Series.
When replacing multiple bool or datetime64 objects and the arguments to to_replace does not match the type of the value being replaced
If a list or an ndarray is passed to to_replace and value but they are not the same length.
See also
Fill NA values.
Replace values based on boolean condition.
Simple string replacement.
Notes
Regex substitution is performed under the hood with re.sub. The rules for substitution for re.sub are the same.
Regular expressions will only substitute on strings, meaning you cannot provide, for example, a regular expression matching floating point numbers and expect the columns in your frame that have a numeric dtype to be matched. However, if those floating point numbers are strings, then you can do this.
This method has a lot of options. You are encouraged to experiment and play with this method to gain intuition about how it works.
When dict is used as the to_replace value, it is like key(s) in the dict are the to_replace part and value(s) in the dict are the value parameter.
Examples
Scalar `to_replace` and `value`
List-like `to_replace`
dict-like `to_replace`
Regular expression `to_replace`
Compare the behavior of s.replace({'a': None}) and s.replace('a', None) to understand the peculiarities of the to_replace parameter:
When one uses a dict as the to_replace value, it is like the value(s) in the dict are equal to the value parameter. s.replace({'a': None}) is equivalent to s.replace(to_replace={'a': None}, value=None, method=None):
When value is not explicitly passed and to_replace is a scalar, list or tuple, replace uses the method parameter (default ‘pad’) to do the replacement. So this is why the ‘a’ values are being replaced by 10 in rows 1 and 2 and ‘b’ in row 4 in this case.
On the other hand, if None is explicitly passed for value, it will be respected:
Changed in version 1.4.0: Previously the explicit None was silently ignored.


Resample time-series data.
Convenience method for frequency conversion and resampling of time series. The object must have a datetime-like index (DatetimeIndex, PeriodIndex, or TimedeltaIndex), or the caller must pass the label of a datetime-like series/index to the on/level keyword parameter.
The offset string or object representing target conversion.
Which axis to use for up- or down-sampling. For Series this will default to 0, i.e. along the rows. Must be DatetimeIndex, TimedeltaIndex or PeriodIndex.
Which side of bin interval is closed. The default is ‘left’ for all frequency offsets except for ‘M’, ‘A’, ‘Q’, ‘BM’, ‘BA’, ‘BQ’, and ‘W’ which all have a default of ‘right’.
Which bin edge label to label bucket with. The default is ‘left’ for all frequency offsets except for ‘M’, ‘A’, ‘Q’, ‘BM’, ‘BA’, ‘BQ’, and ‘W’ which all have a default of ‘right’.
For PeriodIndex only, controls whether to use the start or end of rule.
Pass ‘timestamp’ to convert the resulting index to a DateTimeIndex or ‘period’ to convert it to a PeriodIndex. By default the input representation is retained.
Adjust the resampled time labels.
Deprecated since version 1.1.0: You should add the loffset to the df.index after the resample. See below.
For frequencies that evenly subdivide 1 day, the “origin” of the aggregated intervals. For example, for ‘5min’ frequency, base could range from 0 through 4. Defaults to 0.
Deprecated since version 1.1.0: The new arguments that you should use are ‘offset’ or ‘origin’.
For a DataFrame, column to use instead of index for resampling. Column must be datetime-like.
For a MultiIndex, level (name or number) to use for resampling. level must be datetime-like.
The timestamp on which to adjust the grouping. The timezone of origin must match the timezone of the index. If string, must be one of the following:
‘epoch’: origin is 1970-01-01
‘start’: origin is the first value of the timeseries
‘start_day’: origin is the first day at midnight of the timeseries
New in version 1.1.0.
‘end’: origin is the last value of the timeseries
‘end_day’: origin is the ceiling midnight of the last day
New in version 1.3.0.
An offset timedelta added to the origin.
New in version 1.1.0.
Resampler object.
See also
Resample a Series.
Resample a DataFrame.
Group DataFrame by mapping, function, label, or list of labels.
Reindex a DataFrame with the given frequency without grouping.
Notes
See the user guide for more.
To learn more about the offset strings, please see this link.
Examples
Start by creating a series with 9 one minute timestamps.
Downsample the series into 3 minute bins and sum the values of the timestamps falling into a bin.
Downsample the series into 3 minute bins as above, but label each bin using the right edge instead of the left. Please note that the value in the bucket used as the label is not included in the bucket, which it labels. For example, in the original series the bucket 2000-01-01 00:03:00 contains the value 3, but the summed value in the resampled bucket with the label 2000-01-01 00:03:00 does not include 3 (if it did, the summed value would be 6, not 3). To include this value close the right side of the bin interval as illustrated in the example below this one.
Downsample the series into 3 minute bins as above, but close the right side of the bin interval.
Upsample the series into 30 second bins.
Upsample the series into 30 second bins and fill the NaN values using the pad method.
Upsample the series into 30 second bins and fill the NaN values using the bfill method.
Pass a custom function via apply
For a Series with a PeriodIndex, the keyword convention can be used to control whether to use the start or end of rule.
Resample a year by quarter using ‘start’ convention. Values are assigned to the first quarter of the period.
Resample quarters by month using ‘end’ convention. Values are assigned to the last month of the period.
For DataFrame objects, the keyword on can be used to specify the column instead of the index for resampling.
For a DataFrame with MultiIndex, the keyword level can be used to specify on which level the resampling needs to take place.
If you want to adjust the start of the bins based on a fixed timestamp:
If you want to adjust the start of the bins with an offset Timedelta, the two following lines are equivalent:
If you want to take the largest Timestamp as the end of the bins:
In contrast with the start_day, you can use end_day to take the ceiling midnight of the largest Timestamp as the end of the bins and drop the bins not containing data:
To replace the use of the deprecated base argument, you can now use offset, in this example it is equivalent to have base=2:
To replace the use of the deprecated loffset argument:


Reset the index, or a level of it.
Reset the index of the DataFrame, and use the default one instead. If the DataFrame has a MultiIndex, this method can remove one or more levels.
Only remove the given levels from the index. Removes all levels by default.
Do not try to insert index into dataframe columns. This resets the index to the default integer index.
Modify the DataFrame in place (do not create a new object).
If the columns have multiple levels, determines which level the labels are inserted into. By default it is inserted into the first level.
If the columns have multiple levels, determines how the other levels are named. If None then the index name is repeated.
DataFrame with the new index or None if inplace=True.
See also
Opposite of reset_index.
Change to new indices or expand indices.
Change to same indices as other DataFrame.
Examples
When we reset the index, the old index is added as a column, and a new sequential index is used:
We can use the drop parameter to avoid the old index being added as a column:
You can also use reset_index with MultiIndex.
If the index has multiple levels, we can reset a subset of them:
If we are not dropping the index, by default, it is placed in the top level. We can place it in another level:
When the index is inserted under another level, we can specify under which one with the parameter col_fill:
If we specify a nonexistent level for col_fill, it is created:


Get Integer division of dataframe and other, element-wise (binary operator rfloordiv).
Equivalent to other // dataframe, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, floordiv.
Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.
Any single or multiple element data structure, or list-like object.
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’). For Series input, axis to match Series index on.
Broadcast across a level, matching Index values on the passed MultiIndex level.
Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing.
Result of the arithmetic operation.
See also
Add DataFrames.
Subtract DataFrames.
Multiply DataFrames.
Divide DataFrames (float division).
Divide DataFrames (float division).
Divide DataFrames (integer division).
Calculate modulo (remainder after division).
Calculate exponential power.
Notes
Mismatched indices will be unioned together.
Examples
Add a scalar with operator version which return the same results.
Divide by constant with reverse version.
Subtract a list and Series by axis with operator version.
Multiply a DataFrame of different shape with operator version.
Divide by a MultiIndex by level.