Get Modulo of dataframe and other, element-wise (binary operator rmod).
Equivalent to other % dataframe, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, mod.
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 Multiplication of dataframe and other, element-wise (binary operator rmul).
Equivalent to other * dataframe, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, mul.
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.


Provide rolling window calculations.
Size of the moving window.
If an integer, the fixed number of observations used for each window.
If an offset, the time period of each window. Each window will be a variable sized based on the observations included in the time-period. This is only valid for datetimelike indexes. To learn more about the offsets & frequency strings, please see this link.
If a BaseIndexer subclass, the window boundaries based on the defined get_window_bounds method. Additional rolling keyword arguments, namely min_periods, center, and closed will be passed to get_window_bounds.
Minimum number of observations in window required to have a value; otherwise, result is np.nan.
For a window that is specified by an offset, min_periods will default to 1.
For a window that is specified by an integer, min_periods will default to the size of the window.
If False, set the window labels as the right edge of the window index.
If True, set the window labels as the center of the window index.
If None, all points are evenly weighted.
If a string, it must be a valid scipy.signal window function.
Certain Scipy window types require additional parameters to be passed in the aggregation function. The additional parameters must match the keywords specified in the Scipy window type method signature.
For a DataFrame, a column label or Index level on which to calculate the rolling window, rather than the DataFrame’s index.
Provided integer column is ignored and excluded from result since an integer index is not used to calculate the rolling window.
If 0 or 'index', roll across the rows.
If 1 or 'columns', roll across the columns.
If 'right', the first point in the window is excluded from calculations.
If 'left', the last point in the window is excluded from calculations.
If 'both', the no points in the window are excluded from calculations.
If 'neither', the first and last points in the window are excluded from calculations.
Default None ('right').
Changed in version 1.2.0: The closed parameter with fixed windows is now supported.
New in version 1.3.0.
Execute the rolling operation per single column or row ('single') or over the entire object ('table').
This argument is only implemented when specifying engine='numba' in the method call.
See also
Provides expanding transformations.
Provides exponential weighted functions.
Notes
See Windowing Operations for further usage details and examples.
Examples
window
Rolling sum with a window length of 2 observations.
Rolling sum with a window span of 2 seconds.
Rolling sum with forward looking windows with 2 observations.
min_periods
Rolling sum with a window length of 2 observations, but only needs a minimum of 1 observation to calculate a value.
center
Rolling sum with the result assigned to the center of the window index.
win_type
Rolling sum with a window length of 2, using the Scipy 'gaussian' window type. std is required in the aggregation function.


Round a DataFrame to a variable number of decimal places.
Number of decimal places to round each column to. If an int is given, round each column to the same number of places. Otherwise dict and Series round to variable numbers of places. Column names should be in the keys if decimals is a dict-like, or in the index if decimals is a Series. Any columns not included in decimals will be left as is. Elements of decimals which are not columns of the input will be ignored.
Additional keywords have no effect but might be accepted for compatibility with numpy.
Additional keywords have no effect but might be accepted for compatibility with numpy.
A DataFrame with the affected columns rounded to the specified number of decimal places.
See also
Round a numpy array to the given number of decimals.
Round a Series to the given number of decimals.
Examples
By providing an integer each column is rounded to the same number of decimal places
With a dict, the number of places for specific columns can be specified with the column names as key and the number of decimal places as value
Using a Series, the number of places for specific columns can be specified with the column names as index and the number of decimal places as value


Get Exponential power of dataframe and other, element-wise (binary operator rpow).
Equivalent to other ** dataframe, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, pow.
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 Subtraction of dataframe and other, element-wise (binary operator rsub).
Equivalent to other - dataframe, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, sub.
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 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.


Return a random sample of items from an axis of object.
You can use random_state for reproducibility.
Number of items from axis to return. Cannot be used with frac. Default = 1 if frac = None.
Fraction of axis items to return. Cannot be used with n.
Allow or disallow sampling of the same row more than once.
Default ‘None’ results in equal probability weighting. If passed a Series, will align with target object on index. Index values in weights not found in sampled object will be ignored and index values in sampled object not in weights will be assigned weights of zero. If called on a DataFrame, will accept the name of a column when axis = 0. Unless weights are a Series, weights must be same length as axis being sampled. If weights do not sum to 1, they will be normalized to sum to 1. Missing values in the weights column will be treated as zero. Infinite values not allowed.
If int, array-like, or BitGenerator, seed for random number generator. If np.random.RandomState or np.random.Generator, use as given.
Changed in version 1.1.0: array-like and BitGenerator object now passed to np.random.RandomState() as seed
Changed in version 1.4.0: np.random.Generator objects now accepted
Axis to sample. Accepts axis number or name. Default is stat axis for given data type (0 for Series and DataFrames).
If True, the resulting index will be labeled 0, 1, …, n - 1.
New in version 1.3.0.
A new object of same type as caller containing n items randomly sampled from the caller object.
See also
Generates random samples from each group of a DataFrame object.
Generates random samples from each group of a Series object.
Generates a random sample from a given 1-D numpy array.
Notes
If frac > 1, replacement should be set to True.
Examples
Extract 3 random elements from the Series df['num_legs']: Note that we use random_state to ensure the reproducibility of the examples.
A random 50% sample of the DataFrame with replacement:
An upsample sample of the DataFrame with replacement: Note that replace parameter has to be True for frac parameter > 1.
Using a DataFrame column as weights. Rows with larger value in the num_specimen_seen column are more likely to be sampled.


Return a subset of the DataFrame’s columns based on the column dtypes.
A selection of dtypes or strings to be included/excluded. At least one of these parameters must be supplied.
The subset of the frame including the dtypes in include and excluding the dtypes in exclude.
If both of include and exclude are empty
If include and exclude have overlapping elements
If any kind of string dtype is passed in.
See also
Return Series with the data type of each column.
Notes
To select all numeric types, use np.number or 'number'
To select strings you must use the object dtype, but note that this will return all object dtype columns
See the numpy dtype hierarchy
To select datetimes, use np.datetime64, 'datetime' or 'datetime64'
To select timedeltas, use np.timedelta64, 'timedelta' or 'timedelta64'
To select Pandas categorical dtypes, use 'category'
To select Pandas datetimetz dtypes, use 'datetimetz' (new in 0.20.0) or 'datetime64[ns, tz]'
Examples


Return unbiased standard error of the mean over requested axis.
Normalized by N-1 by default. This can be changed using the ddof argument
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.
Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements.
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.


Assign desired index to given axis.
Indexes for column or row labels can be changed by assigning a list-like or Index.
The values for the new index.
The axis to update. The value 0 identifies the rows, and 1 identifies the columns.
Whether to return a new DataFrame instance.
An object of type DataFrame or None if inplace=True.
See also
Alter the name of the index or columns.
Examples
Change the row labels.
Change the column labels.
Now, update the labels inplace.


Return a new object with updated flags.
Whether the returned object allows duplicate labels.
The same type as the caller.
See also
Global metadata applying to this dataset.
Global flags applying to this object.
Notes
This method returns a new object that’s a view on the same data as the input. Mutating the input or the output values will be reflected in the other.
This method is intended to be used in method chains.
“Flags” differ from “metadata”. Flags reflect properties of the pandas object (the Series or DataFrame). Metadata refer to properties of the dataset, and should be stored in DataFrame.attrs.
Examples


Set the DataFrame index using existing columns.
Set the DataFrame index (row labels) using one or more existing columns or arrays (of the correct length). The index can replace the existing index or expand on it.
This parameter can be either a single column key, a single array of the same length as the calling DataFrame, or a list containing an arbitrary combination of column keys and arrays. Here, “array” encompasses Series, Index, np.ndarray, and instances of Iterator.
Delete columns to be used as the new index.
Whether to append columns to existing index.
If True, modifies the DataFrame in place (do not create a new object).
Check the new index for duplicates. Otherwise defer the check until necessary. Setting to False will improve the performance of this method.
Changed row labels or None if inplace=True.
See also
Opposite of set_index.
Change to new indices or expand indices.
Change to same indices as other DataFrame.
Examples
Set the index to become the ‘month’ column:
Create a MultiIndex using columns ‘year’ and ‘month’:
Create a MultiIndex using an Index and a column:
Create a MultiIndex using two Series:


Return a tuple representing the dimensionality of the DataFrame.
See also
Tuple of array dimensions.
Examples


Shift index by desired number of periods with an optional time freq.
When freq is not passed, shift the index without realigning the data. If freq is passed (in this case, the index must be date or datetime, or it will raise a NotImplementedError), the index will be increased using the periods and the freq. freq can be inferred when specified as “infer” as long as either freq or inferred_freq attribute is set in the index.
Number of periods to shift. Can be positive or negative.
Offset to use from the tseries module or time rule (e.g. ‘EOM’). If freq is specified then the index values are shifted but the data is not realigned. That is, use freq if you would like to extend the index when shifting and preserve the original data. If freq is specified as “infer” then it will be inferred from the freq or inferred_freq attributes of the index. If neither of those attributes exist, a ValueError is thrown.
Shift direction.
The scalar value to use for newly introduced missing values. the default depends on the dtype of self. For numeric data, np.nan is used. For datetime, timedelta, or period data, etc. NaT is used. For extension dtypes, self.dtype.na_value is used.
Changed in version 1.1.0.
Copy of input object, shifted.
See also
Shift values of Index.
Shift values of DatetimeIndex.
Shift values of PeriodIndex.
Shift the time index, using the index’s frequency if available.
Examples


Return an int representing the number of elements in this object.
Return the number of rows if Series. Otherwise return the number of rows times number of columns if DataFrame.
See also
Number of elements in the array.
Examples


Return unbiased skew over requested axis.
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.


Equivalent to shift without copying data. The shifted data will not include the dropped periods and the shifted axis will be smaller than the original.
Deprecated since version 1.2.0: slice_shift is deprecated, use DataFrame/Series.shift instead.
Number of periods to move, can be positive or negative.
Notes
While the slice_shift is faster than shift, you may pay for it later during alignment.


Sort object by labels (along an axis).
Returns a new DataFrame sorted by label if inplace argument is False, otherwise updates the original DataFrame and returns None.
The axis along which to sort. The value 0 identifies the rows, and 1 identifies the columns.
If not None, sort on values in specified index level(s).
Sort ascending vs. descending. When the index is a MultiIndex the sort direction can be controlled for each level individually.
If True, perform operation in-place.
Choice of sorting algorithm. See also numpy.sort() for more information. mergesort and stable are the only stable algorithms. For DataFrames, this option is only applied when sorting on a single column or label.
Puts NaNs at the beginning if first; last puts NaNs at the end. Not implemented for MultiIndex.
If True and sorting by level and index is multilevel, sort by other levels too (in order) after sorting by specified level.
If True, the resulting axis will be labeled 0, 1, …, n - 1.
New in version 1.0.0.
If not None, apply the key function to the index values before sorting. This is similar to the key argument in the builtin sorted() function, with the notable difference that this key function should be vectorized. It should expect an Index and return an Index of the same shape. For MultiIndex inputs, the key is applied per level.
New in version 1.1.0.
The original DataFrame sorted by the labels or None if inplace=True.
See also
Sort Series by the index.
Sort DataFrame by the value.
Sort Series by the value.
Examples
By default, it sorts in ascending order, to sort in descending order, use ascending=False
A key function can be specified which is applied to the index before sorting. For a MultiIndex this is applied to each level separately.


Sort by the values along either axis.
Name or list of names to sort by.
if axis is 0 or ‘index’ then by may contain index levels and/or column labels.
if axis is 1 or ‘columns’ then by may contain column levels and/or index labels.
Axis to be sorted.
Sort ascending vs. descending. Specify list for multiple sort orders. If this is a list of bools, must match the length of the by.
If True, perform operation in-place.
Choice of sorting algorithm. See also numpy.sort() for more information. mergesort and stable are the only stable algorithms. For DataFrames, this option is only applied when sorting on a single column or label.
Puts NaNs at the beginning if first; last puts NaNs at the end.
If True, the resulting axis will be labeled 0, 1, …, n - 1.
New in version 1.0.0.
Apply the key function to the values before sorting. This is similar to the key argument in the builtin sorted() function, with the notable difference that this key function should be vectorized. It should expect a Series and return a Series with the same shape as the input. It will be applied to each column in by independently.
New in version 1.1.0.
DataFrame with sorted values or None if inplace=True.
See also
Sort a DataFrame by the index.
Similar method for a Series.
Examples
Sort by col1
Sort by multiple columns
Sort Descending
Putting NAs first
Sorting with a key function
Natural sort with the key argument, using the natsort <https://github.com/SethMMorton/natsort> package.


DataFrame accessor for sparse data.
New in version 0.25.0.


Ratio of non-sparse points to total (dense) data points.


Create a new DataFrame from a scipy sparse matrix.
New in version 0.25.0.
Must be convertible to csc format.
Row and column labels to use for the resulting DataFrame. Defaults to a RangeIndex.
Each column of the DataFrame is stored as a arrays.SparseArray.
Examples


Return the contents of the frame as a sparse SciPy COO matrix.
New in version 0.25.0.
If the caller is heterogeneous and contains booleans or objects, the result will be of dtype=object. See Notes.
Notes
The dtype will be the lowest-common-denominator type (implicit upcasting); that is to say if the dtypes (even of numeric types) are mixed, the one that accommodates all will be chosen.
e.g. If the dtypes are float16 and float32, dtype will be upcast to float32. By numpy.find_common_type convention, mixing int64 and and uint64 will result in a float64 dtype.


Convert a DataFrame with sparse values to dense.
New in version 0.25.0.
A DataFrame with the same values stored as dense arrays.
Examples


Squeeze 1 dimensional axis objects into scalars.
Series or DataFrames with a single element are squeezed to a scalar. DataFrames with a single column or a single row are squeezed to a Series. Otherwise the object is unchanged.
This method is most useful when you don’t know if your object is a Series or DataFrame, but you do know it has just a single column. In that case you can safely call squeeze to ensure you have a Series.
A specific axis to squeeze. By default, all length-1 axes are squeezed.
The projection after squeezing axis or all the axes.
See also
Integer-location based indexing for selecting scalars.
Integer-location based indexing for selecting Series.
Inverse of DataFrame.squeeze for a single-column DataFrame.
Examples
Slicing might produce a Series with a single value:
Squeezing objects with more than one value in every axis does nothing:
Squeezing is even more effective when used with DataFrames.
Slicing a single column will produce a DataFrame with the columns having only one value:
So the columns can be squeezed down, resulting in a Series:
Slicing a single row from a single column will produce a single scalar DataFrame:
Squeezing the rows produces a single scalar Series:
Squeezing all axes will project directly into a scalar:


Stack the prescribed level(s) from columns to index.
Return a reshaped DataFrame or Series having a multi-level index with one or more new inner-most levels compared to the current DataFrame. The new inner-most levels are created by pivoting the columns of the current dataframe:
if the columns have a single level, the output is a Series;
if the columns have multiple levels, the new index level(s) is (are) taken from the prescribed level(s) and the output is a DataFrame.
Level(s) to stack from the column axis onto the index axis, defined as one index or label, or a list of indices or labels.
Whether to drop rows in the resulting Frame/Series with missing values. Stacking a column level onto the index axis can create combinations of index and column values that are missing from the original dataframe. See Examples section.
Stacked dataframe or series.
See also
Unstack prescribed level(s) from index axis onto column axis.
Reshape dataframe from long format to wide format.
Create a spreadsheet-style pivot table as a DataFrame.
Notes
The function is named by analogy with a collection of books being reorganized from being side by side on a horizontal position (the columns of the dataframe) to being stacked vertically on top of each other (in the index of the dataframe).
Examples
Single level columns
Stacking a dataframe with a single level column axis returns a Series:
Multi level columns: simple case
Stacking a dataframe with a multi-level column axis:
Missing values
It is common to have missing values when stacking a dataframe with multi-level columns, as the stacked dataframe typically has more values than the original dataframe. Missing values are filled with NaNs:
Prescribing the level(s) to be stacked
The first parameter controls which level or levels are stacked:
Dropping missing values
Note that rows where all values are missing are dropped by default but this behaviour can be controlled via the dropna keyword parameter:


Return sample standard deviation over requested axis.
Normalized by N-1 by default. This can be changed using the ddof argument.
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.
Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements.
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
Notes
To have the same behaviour as numpy.std, use ddof=0 (instead of the default ddof=1)
Examples
The standard deviation of the columns can be found as follows:
Alternatively, ddof=0 can be set to normalize by N instead of N-1:


Returns a Styler object.
Contains methods for building a styled HTML representation of the DataFrame.
See also
Helps style a DataFrame or Series according to the data with HTML and CSS.


Get Subtraction of dataframe and other, element-wise (binary operator sub).
Equivalent to dataframe - other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rsub.
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 sum of the values over the requested axis.
This is equivalent to the method numpy.sum.
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 sum of an empty or all-NA Series is 0.
This can be controlled with the min_count parameter. For example, if you’d like the sum of an empty series to be NaN, pass min_count=1.
Thanks to the skipna parameter, min_count handles all-NA and empty series identically.


Interchange axes and swap values axes appropriately.


Swap levels i and j in a MultiIndex.
Default is to swap the two innermost levels of the index.
Levels of the indices to be swapped. Can pass level name as string.
The axis to swap levels on. 0 or ‘index’ for row-wise, 1 or ‘columns’ for column-wise.
DataFrame with levels swapped in MultiIndex.
Examples
In the following example, we will swap the levels of the indices. Here, we will swap the levels column-wise, but levels can be swapped row-wise in a similar manner. Note that column-wise is the default behaviour. By not supplying any arguments for i and j, we swap the last and second to last indices.
By supplying one argument, we can choose which index to swap the last index with. We can for example swap the first index with the last one as follows.
We can also define explicitly which indices we want to swap by supplying values for both i and j. Here, we for example swap the first and second indices.


Return the last n rows.
This function returns last n rows from the object based on position. It is useful for quickly verifying data, for example, after sorting or appending rows.
For negative values of n, this function returns all rows except the first n rows, equivalent to df[n:].
Number of rows to select.
The last n rows of the caller object.
See also
The first n rows of the caller object.
Examples
Viewing the last 5 lines
Viewing the last n lines (three in this case)
For negative values of n


Return the elements in the given positional indices along an axis.
This means that we are not indexing according to actual values in the index attribute of the object. We are indexing according to the actual position of the element in the object.
An array of ints indicating which positions to take.
The axis on which to select elements. 0 means that we are selecting rows, 1 means that we are selecting columns.
Before pandas 1.0, is_copy=False can be specified to ensure that the return value is an actual copy. Starting with pandas 1.0, take always returns a copy, and the keyword is therefore deprecated.
Deprecated since version 1.0.0.
For compatibility with numpy.take(). Has no effect on the output.
An array-like containing the elements taken from the object.
See also
Select a subset of a DataFrame by labels.
Select a subset of a DataFrame by positions.
Take elements from an array along an axis.
Examples
Take elements at positions 0 and 3 along the axis 0 (default).
Note how the actual indices selected (0 and 1) do not correspond to our selected indices 0 and 3. That’s because we are selecting the 0th and 3rd rows, not rows whose indices equal 0 and 3.
Take elements at indices 1 and 2 along the axis 1 (column selection).
We may take elements using negative integers for positive indices, starting from the end of the object, just like with Python lists.


Copy object to the system clipboard.
Write a text representation of object to the system clipboard. This can be pasted into Excel, for example.
Produce output in a csv format for easy pasting into excel.
True, use the provided separator for csv pasting.
False, write a string representation of the object to the clipboard.
Field delimiter.
These parameters will be passed to DataFrame.to_csv.
See also
Write a DataFrame to a comma-separated values (csv) file.
Read text from clipboard and pass to read_csv.
Notes
Requirements for your platform.
Linux : xclip, or xsel (with PyQt4 modules)
Windows : none
macOS : none
Examples
Copy the contents of a DataFrame to the clipboard.
We can omit the index by passing the keyword index and setting it to false.


Write object to a comma-separated values (csv) file.
String, path object (implementing os.PathLike[str]), or file-like object implementing a write() function. If None, the result is returned as a string. If a non-binary file object is passed, it should be opened with newline=’’, disabling universal newlines. If a binary file object is passed, mode might need to contain a ‘b’.
Changed in version 1.2.0: Support for binary file objects was introduced.
String of length 1. Field delimiter for the output file.
Missing data representation.
Format string for floating point numbers.
Columns to write.
Write out the column names. If a list of strings is given it is assumed to be aliases for the column names.
Write row names (index).
Column label for index column(s) if desired. If None is given, and header and index are True, then the index names are used. A sequence should be given if the object uses MultiIndex. If False do not print fields for index names. Use index_label=False for easier importing in R.
Python write mode, default ‘w’.
A string representing the encoding to use in the output file, defaults to ‘utf-8’. encoding is not supported if path_or_buf is a non-binary file object.
For on-the-fly compression of the output data. If ‘infer’ and ‘%s’ path-like, then detect compression from the following extensions: ‘.gz’, ‘.bz2’, ‘.zip’, ‘.xz’, or ‘.zst’ (otherwise no compression). Set to None for no compression. Can also be a dict with key 'method' set to one of {'zip', 'gzip', 'bz2', 'zstd'} and other key-value pairs are forwarded to zipfile.ZipFile, gzip.GzipFile, bz2.BZ2File, or zstandard.ZstdDecompressor, respectively. As an example, the following could be passed for faster compression and to create a reproducible gzip archive: compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}.
Changed in version 1.0.0: May now be a dict with key ‘method’ as compression mode and other entries as additional compression options if compression mode is ‘zip’.
Changed in version 1.1.0: Passing compression options as keys in dict is supported for compression modes ‘gzip’, ‘bz2’, ‘zstd’, and ‘zip’.
Changed in version 1.2.0: Compression is supported for binary file objects.
Changed in version 1.2.0: Previous versions forwarded dict entries for ‘gzip’ to gzip.open instead of gzip.GzipFile which prevented setting mtime.
Defaults to csv.QUOTE_MINIMAL. If you have set a float_format then floats are converted to strings and thus csv.QUOTE_NONNUMERIC will treat them as non-numeric.
String of length 1. Character used to quote fields.
The newline character or character sequence to use in the output file. Defaults to os.linesep, which depends on the OS in which this method is called (’\n’ for linux, ‘\r\n’ for Windows, i.e.).
Rows to write at a time.
Format string for datetime objects.
Control quoting of quotechar inside a field.
String of length 1. Character used to escape sep and quotechar when appropriate.
Character recognized as decimal separator. E.g. use ‘,’ for European data.
Specifies how encoding and decoding errors are to be handled. See the errors argument for open() for a full list of options.
New in version 1.1.0.
Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec. Please see fsspec and urllib for more details.
New in version 1.2.0.
If path_or_buf is None, returns the resulting csv format as a string. Otherwise returns None.
See also
Load a CSV file into a DataFrame.
Write DataFrame to an Excel file.
Examples
Create ‘out.zip’ containing ‘out.csv’
To write a csv file to a new folder or nested folder you will first need to create it using either Pathlib or os:


Convert the DataFrame to a dictionary.
The type of the key-value pairs can be customized with the parameters (see below).
Determines the type of the values of the dictionary.
‘dict’ (default) : dict like {column -> {index -> value}}
‘list’ : dict like {column -> [values]}
‘series’ : dict like {column -> Series(values)}
‘split’ : dict like {‘index’ -> [index], ‘columns’ -> [columns], ‘data’ -> [values]}
‘tight’ : dict like {‘index’ -> [index], ‘columns’ -> [columns], ‘data’ -> [values], ‘index_names’ -> [index.names], ‘column_names’ -> [column.names]}
‘records’ : list like [{column -> value}, … , {column -> value}]
‘index’ : dict like {index -> {column -> value}}
Abbreviations are allowed. s indicates series and sp indicates split.
New in version 1.4.0: ‘tight’ as an allowed value for the orient argument
The collections.abc.Mapping subclass used for all Mappings in the return value. Can be the actual class or an empty instance of the mapping type you want. If you want a collections.defaultdict, you must pass it initialized.
Return a collections.abc.Mapping object representing the DataFrame. The resulting transformation depends on the orient parameter.
See also
Create a DataFrame from a dictionary.
Convert a DataFrame to JSON format.
Examples
You can specify the return orientation.
You can also specify the mapping type.
If you want a defaultdict, you need to initialize it:


Write object to an Excel sheet.
To write a single object to an Excel .xlsx file it is only necessary to specify a target file name. To write to multiple sheets it is necessary to create an ExcelWriter object with a target file name, and specify a sheet in the file to write to.
Multiple sheets may be written to by specifying unique sheet_name. With all data written to the file it is necessary to save the changes. Note that creating an ExcelWriter object with a file name that already exists will result in the contents of the existing file being erased.
File path or existing ExcelWriter.
Name of sheet which will contain DataFrame.
Missing data representation.
Format string for floating point numbers. For example float_format="%.2f" will format 0.1234 to 0.12.
Columns to write.
Write out the column names. If a list of string is given it is assumed to be aliases for the column names.
Write row names (index).
Column label for index column(s) if desired. If not specified, and header and index are True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex.
Upper left cell row to dump data frame.
Upper left cell column to dump data frame.
Write engine to use, ‘openpyxl’ or ‘xlsxwriter’. You can also set this via the options io.excel.xlsx.writer, io.excel.xls.writer, and io.excel.xlsm.writer.
Deprecated since version 1.2.0: As the xlwt package is no longer maintained, the xlwt engine will be removed in a future version of pandas.
Write MultiIndex and Hierarchical Rows as merged cells.
Encoding of the resulting excel file. Only necessary for xlwt, other writers support unicode natively.
Representation for infinity (there is no native representation for infinity in Excel).
Display more information in the error logs.
Specifies the one-based bottommost row and rightmost column that is to be frozen.
Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec. Please see fsspec and urllib for more details.
New in version 1.2.0.
See also
Write DataFrame to a comma-separated values (csv) file.
Class for writing DataFrame objects into excel sheets.
Read an Excel file into a pandas DataFrame.
Read a comma-separated values (csv) file into DataFrame.
Notes
For compatibility with to_csv(), to_excel serializes lists and dicts to strings before writing.
Once a workbook has been saved it is not possible to write further data without rewriting the whole workbook.
Examples
Create, write to and save a workbook:
To specify the sheet name:
If you wish to write to more than one sheet in the workbook, it is necessary to specify an ExcelWriter object:
ExcelWriter can also be used to append to an existing Excel file:
To set the library that is used to write the Excel file, you can pass the engine keyword (the default engine is automatically chosen depending on the file extension):


Write a DataFrame to the binary Feather format.
String, path object (implementing os.PathLike[str]), or file-like object implementing a binary write() function. If a string or a path, it will be used as Root Directory path when writing a partitioned dataset.
Additional keywords passed to pyarrow.feather.write_feather(). Starting with pyarrow 0.17, this includes the compression, compression_level, chunksize and version keywords.
New in version 1.1.0.
Notes
This function writes the dataframe as a feather file. Requires a default index. For saving the DataFrame with your custom index use a method that supports custom indices e.g. to_parquet.


Write a DataFrame to a Google BigQuery table.
This function requires the pandas-gbq package.
See the How to authenticate with Google BigQuery guide for authentication instructions.
Name of table to be written, in the form dataset.tablename.
Google BigQuery Account project ID. Optional when available from the environment.
Number of rows to be inserted in each chunk from the dataframe. Set to None to load the whole dataframe at once.
Force Google BigQuery to re-authenticate the user. This is useful if multiple accounts are used.
Behavior when the destination table exists. Value can be one of:
If table exists raise pandas_gbq.gbq.TableCreationError.
If table exists, drop it, recreate it, and insert data.
If table exists, insert data. Create if does not exist.
Use the local webserver flow instead of the console flow when getting user credentials.
New in version 0.2.0 of pandas-gbq.
List of BigQuery table fields to which according DataFrame columns conform to, e.g. [{'name': 'col1', 'type':
'STRING'},...]. If schema is not provided, it will be generated according to dtypes of DataFrame columns. See BigQuery API documentation on available names of a field.
New in version 0.3.1 of pandas-gbq.
Location where the load job should run. See the BigQuery locations documentation for a list of available locations. The location must match that of the target dataset.
New in version 0.5.0 of pandas-gbq.
Use the library tqdm to show the progress bar for the upload, chunk by chunk.
New in version 0.5.0 of pandas-gbq.
Credentials for accessing Google APIs. Use this parameter to override default credentials, such as to use Compute Engine google.auth.compute_engine.Credentials or Service Account google.oauth2.service_account.Credentials directly.
New in version 0.8.0 of pandas-gbq.
See also
This function in the pandas-gbq library.
Read a DataFrame from Google BigQuery.


Write the contained data to an HDF5 file using HDFStore.
Hierarchical Data Format (HDF) is self-describing, allowing an application to interpret the structure and contents of a file with no outside information. One HDF file can hold a mix of related objects which can be accessed as a group or as individual objects.
In order to add another DataFrame or Series to an existing HDF file please use append mode and a different a key.
Warning
One can store a subclass of DataFrame or Series to HDF5, but the type of the subclass is lost upon storing.
For more information see the user guide.
File path or HDFStore object.
Identifier for the group in the store.
Mode to open file:
‘w’: write, a new file is created (an existing file with the same name would be deleted).
‘a’: append, an existing file is opened for reading and writing, and if the file does not exist it is created.
‘r+’: similar to ‘a’, but the file must already exist.
Specifies a compression level for data. A value of 0 or None disables compression.
Specifies the compression library to be used. As of v0.20.2 these additional compressors for Blosc are supported (default if no compressor specified: ‘blosc:blosclz’): {‘blosc:blosclz’, ‘blosc:lz4’, ‘blosc:lz4hc’, ‘blosc:snappy’, ‘blosc:zlib’, ‘blosc:zstd’}. Specifying a compression library which is not available issues a ValueError.
For Table formats, append the input data to the existing.
Possible values:
‘fixed’: Fixed format. Fast writing/reading. Not-appendable, nor searchable.
‘table’: Table format. Write as a PyTables Table structure which may perform worse but allow more flexible operations like searching / selecting subsets of the data.
If None, pd.get_option(‘io.hdf.default_format’) is checked, followed by fallback to “fixed”.
Specifies how encoding and decoding errors are to be handled. See the errors argument for open() for a full list of options.
Map column names to minimum string sizes for columns.
How to represent null values as str. Not allowed with append=True.
List of columns to create as indexed data columns for on-disk queries, or True to use all columns. By default only the axes of the object are indexed. See Query via data columns. Applicable only to format=’table’.
See also
Read from HDF file.
Write a DataFrame to the binary parquet format.
Write to a SQL table.
Write out feather-format for DataFrames.
Write out to a csv file.
Examples
We can add another object to the same file:
Reading from HDF file:


Render a DataFrame as an HTML table.
Buffer to write to. If None, the output is returned as a string.
The subset of columns to write. Writes all columns by default.
The minimum width of each column in CSS length units. An int is assumed to be px units.
New in version 0.25.0: Ability to use str.
Whether to print column labels, default True.
Whether to print index (row) labels.
String representation of NaN to use.
Formatter functions to apply to columns’ elements by position or name. The result of each function must be a unicode string. List/tuple must be of length equal to the number of columns.
Formatter function to apply to columns’ elements if they are floats. This function must return a unicode string and will be applied only to the non-NaN elements, with NaN being handled by na_rep.
Changed in version 1.2.0.
Set to False for a DataFrame with a hierarchical index to print every multiindex key at each row.
Prints the names of the indexes.
How to justify the column labels. If None uses the option from the print configuration (controlled by set_option), ‘right’ out of the box. Valid values are
left
right
center
justify
justify-all
start
end
inherit
match-parent
initial
unset.
Maximum number of rows to display in the console.
Maximum number of columns to display in the console.
Display DataFrame dimensions (number of rows by number of columns).
Character recognized as decimal separator, e.g. ‘,’ in Europe.
Make the row labels bold in the output.
CSS class(es) to apply to the resulting html table.
Convert the characters <, >, and & to HTML-safe sequences.
Whether the generated HTML is for IPython Notebook.
A border=border attribute is included in the opening <table> tag. Default pd.options.display.html.border.
A css id is included in the opening <table> tag if specified.
Convert URLs to HTML links.
Set character encoding.
New in version 1.0.
If buf is None, returns the result as a string. Otherwise returns None.
See also
Convert DataFrame to a string.


Convert the object to a JSON string.
Note NaN’s and None will be converted to null and datetime objects will be converted to UNIX timestamps.
String, path object (implementing os.PathLike[str]), or file-like object implementing a write() function. If None, the result is returned as a string.
Indication of expected JSON string format.
Series:
default is ‘index’
allowed values are: {‘split’, ‘records’, ‘index’, ‘table’}.
DataFrame:
default is ‘columns’
allowed values are: {‘split’, ‘records’, ‘index’, ‘columns’, ‘values’, ‘table’}.
The format of the JSON string:
‘split’ : dict like {‘index’ -> [index], ‘columns’ -> [columns], ‘data’ -> [values]}
‘records’ : list like [{column -> value}, … , {column -> value}]
‘index’ : dict like {index -> {column -> value}}
‘columns’ : dict like {column -> {index -> value}}
‘values’ : just the values array
‘table’ : dict like {‘schema’: {schema}, ‘data’: {data}}
Describing the data, where data component is like orient='records'.
Type of date conversion. ‘epoch’ = epoch milliseconds, ‘iso’ = ISO8601. The default depends on the orient. For orient='table', the default is ‘iso’. For all other orients, the default is ‘epoch’.
The number of decimal places to use when encoding floating point values.
Force encoded string to be ASCII.
The time unit to encode to, governs timestamp and ISO8601 precision. One of ‘s’, ‘ms’, ‘us’, ‘ns’ for second, millisecond, microsecond, and nanosecond respectively.
Handler to call if object cannot otherwise be converted to a suitable format for JSON. Should receive a single argument which is the object to convert and return a serialisable object.
If ‘orient’ is ‘records’ write out line-delimited json format. Will throw ValueError if incorrect ‘orient’ since others are not list-like.
For on-the-fly compression of the output data. If ‘infer’ and ‘path_or_buf’ path-like, then detect compression from the following extensions: ‘.gz’, ‘.bz2’, ‘.zip’, ‘.xz’, or ‘.zst’ (otherwise no compression). Set to None for no compression. Can also be a dict with key 'method' set to one of {'zip', 'gzip', 'bz2', 'zstd'} and other key-value pairs are forwarded to zipfile.ZipFile, gzip.GzipFile, bz2.BZ2File, or zstandard.ZstdDecompressor, respectively. As an example, the following could be passed for faster compression and to create a reproducible gzip archive: compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}.
Changed in version 1.4.0: Zstandard support.
Whether to include the index values in the JSON string. Not including the index (index=False) is only supported when orient is ‘split’ or ‘table’.
Length of whitespace used to indent each record.
New in version 1.0.0.
Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec. Please see fsspec and urllib for more details.
New in version 1.2.0.
If path_or_buf is None, returns the resulting json format as a string. Otherwise returns None.
See also
Convert a JSON string to pandas object.
Notes
The behavior of indent=0 varies from the stdlib, which does not indent the output but does insert newlines. Currently, indent=0 and the default indent=None are equivalent in pandas, though this may change in a future release.
orient='table' contains a ‘pandas_version’ field under ‘schema’. This stores the version of pandas used in the latest revision of the schema.
Examples
Encoding/decoding a Dataframe using 'records' formatted JSON. Note that index labels are not preserved with this encoding.
Encoding/decoding a Dataframe using 'index' formatted JSON:
Encoding/decoding a Dataframe using 'columns' formatted JSON:
Encoding/decoding a Dataframe using 'values' formatted JSON:
Encoding with Table Schema:


Render object to a LaTeX tabular, longtable, or nested table.
Requires \usepackage{booktabs}. The output can be copy/pasted into a main LaTeX document or read from an external file with \input{table.tex}.
Changed in version 1.0.0: Added caption and label arguments.
Changed in version 1.2.0: Added position argument, changed meaning of caption argument.
Buffer to write to. If None, the output is returned as a string.
The subset of columns to write. Writes all columns by default.
The minimum width of each column.
Write out the column names. If a list of strings is given, it is assumed to be aliases for the column names.
Write row names (index).
Missing data representation.
Formatter functions to apply to columns’ elements by position or name. The result of each function must be a unicode string. List must be of length equal to the number of columns.
Formatter for floating point numbers. For example float_format="%.2f" and float_format="{:0.2f}".format will both result in 0.1234 being formatted as 0.12.
Set to False for a DataFrame with a hierarchical index to print every multiindex key at each row. By default, the value will be read from the config module.
Prints the names of the indexes.
Make the row labels bold in the output.
The columns format as specified in LaTeX table format e.g. ‘rcl’ for 3 columns. By default, ‘l’ will be used for all columns except columns of numbers, which default to ‘r’.
By default, the value will be read from the pandas config module. Use a longtable environment instead of tabular. Requires adding a usepackage{longtable} to your LaTeX preamble.
By default, the value will be read from the pandas config module. When set to False prevents from escaping latex special characters in column names.
A string representing the encoding to use in the output file, defaults to ‘utf-8’.
Character recognized as decimal separator, e.g. ‘,’ in Europe.
Use multicolumn to enhance MultiIndex columns. The default will be read from the config module.
The alignment for multicolumns, similar to column_format The default will be read from the config module.
Use multirow to enhance MultiIndex rows. Requires adding a usepackage{multirow} to your LaTeX preamble. Will print centered labels (instead of top-aligned) across the contained rows, separating groups via clines. The default will be read from the pandas config module.
Tuple (full_caption, short_caption), which results in \caption[short_caption]{full_caption}; if a single string is passed, no short caption will be set.
New in version 1.0.0.
Changed in version 1.2.0: Optionally allow caption to be a tuple (full_caption, short_caption).
The LaTeX label to be placed inside \label{} in the output. This is used with \ref{} in the main .tex file.
New in version 1.0.0.
The LaTeX positional argument for tables, to be placed after \begin{} in the output.
New in version 1.2.0.
If buf is None, returns the result as a string. Otherwise returns None.
See also
Render a DataFrame to LaTeX with conditional formatting.
Render a DataFrame to a console-friendly tabular output.
Render a DataFrame as an HTML table.
Examples


Print DataFrame in Markdown-friendly format.
New in version 1.0.0.
Buffer to write to. If None, the output is returned as a string.
Mode in which file is opened, “wt” by default.
Add index (row) labels.
New in version 1.1.0.
Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec. Please see fsspec and urllib for more details.
New in version 1.2.0.
These parameters will be passed to tabulate.
DataFrame in Markdown-friendly format.
Notes
Requires the tabulate package.
Examples
Output markdown with a tabulate option.


Convert the DataFrame to a NumPy array.
By default, the dtype of the returned array will be the common NumPy dtype of all types in the DataFrame. For example, if the dtypes are float16 and float32, the results dtype will be float32. This may require copying data and coercing values, which may be expensive.
The dtype to pass to numpy.asarray().
Whether to ensure that the returned value is not a view on another array. Note that copy=False does not ensure that to_numpy() is no-copy. Rather, copy=True ensure that a copy is made, even if not strictly necessary.
The value to use for missing values. The default value depends on dtype and the dtypes of the DataFrame columns.
New in version 1.1.0.
See also
Similar method for Series.
Examples
With heterogeneous data, the lowest common type will have to be used.
For a mix of numeric and non-numeric types, the output array will have object dtype.


Write a DataFrame to the binary parquet format.
This function writes the dataframe as a parquet file. You can choose different parquet backends, and have the option of compression. See the user guide for more details.
String, path object (implementing os.PathLike[str]), or file-like object implementing a binary write() function. If None, the result is returned as bytes. If a string or path, it will be used as Root Directory path when writing a partitioned dataset.
Changed in version 1.2.0.
Previously this was “fname”
Parquet library to use. If ‘auto’, then the option io.parquet.engine is used. The default io.parquet.engine behavior is to try ‘pyarrow’, falling back to ‘fastparquet’ if ‘pyarrow’ is unavailable.
Name of the compression to use. Use None for no compression.
If True, include the dataframe’s index(es) in the file output. If False, they will not be written to the file. If None, similar to True the dataframe’s index(es) will be saved. However, instead of being saved as values, the RangeIndex will be stored as a range in the metadata so it doesn’t require much space and is faster. Other indexes will be included as columns in the file output.
Column names by which to partition the dataset. Columns are partitioned in the order they are given. Must be None if path is not a string.
Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec. Please see fsspec and urllib for more details.
New in version 1.2.0.
Additional arguments passed to the parquet library. See pandas io for more details.
See also
Read a parquet file.
Write a csv file.
Write to a sql table.
Write to hdf.
Notes
This function requires either the fastparquet or pyarrow library.
Examples
If you want to get a buffer to the parquet content you can use a io.BytesIO object, as long as you don’t use partition_cols, which creates multiple files.


Convert DataFrame from DatetimeIndex to PeriodIndex.
Convert DataFrame from DatetimeIndex to PeriodIndex with desired frequency (inferred from index if not passed).
Frequency of the PeriodIndex.
The axis to convert (the index by default).
If False then underlying input data is not copied.
Examples
For the yearly frequency


Pickle (serialize) object to file.
File path where the pickled object will be stored.
For on-the-fly compression of the output data. If ‘infer’ and ‘path’ path-like, then detect compression from the following extensions: ‘.gz’, ‘.bz2’, ‘.zip’, ‘.xz’, or ‘.zst’ (otherwise no compression). Set to None for no compression. Can also be a dict with key 'method' set to one of {'zip', 'gzip', 'bz2', 'zstd'} and other key-value pairs are forwarded to zipfile.ZipFile, gzip.GzipFile, bz2.BZ2File, or zstandard.ZstdDecompressor, respectively. As an example, the following could be passed for faster compression and to create a reproducible gzip archive: compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}.
Int which indicates which protocol should be used by the pickler, default HIGHEST_PROTOCOL (see [1] paragraph 12.1.2). The possible values are 0, 1, 2, 3, 4, 5. A negative value for the protocol parameter is equivalent to setting its value to HIGHEST_PROTOCOL.
https://docs.python.org/3/library/pickle.html.
Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec. Please see fsspec and urllib for more details.
New in version 1.2.0.
See also
Load pickled pandas object (or any object) from file.
Write DataFrame to an HDF5 file.
Write DataFrame to a SQL database.
Write a DataFrame to the binary parquet format.
Examples


Convert DataFrame to a NumPy record array.
Index will be included as the first field of the record array if requested.
Include index in resulting record array, stored in ‘index’ field or using the index label, if set.
If a string or type, the data type to store all columns. If a dictionary, a mapping of column names and indices (zero-indexed) to specific data types.
If a string or type, the data type to store all index levels. If a dictionary, a mapping of index level names and indices (zero-indexed) to specific data types.
This mapping is applied only if index=True.
NumPy ndarray with the DataFrame labels as fields and each row of the DataFrame as entries.
See also
Convert structured or record ndarray to DataFrame.
An ndarray that allows field access using attributes, analogous to typed columns in a spreadsheet.
Examples
If the DataFrame index has no label then the recarray field name is set to ‘index’. If the index has a label then this is used as the field name:
The index can be excluded from the record array:
Data types can be specified for the columns:
As well as for the index:


Write records stored in a DataFrame to a SQL database.
Databases supported by SQLAlchemy [1] are supported. Tables can be newly created, appended to, or overwritten.
Name of SQL table.
Using SQLAlchemy makes it possible to use any DB supported by that library. Legacy support is provided for sqlite3.Connection objects. The user is responsible for engine disposal and connection closure for the SQLAlchemy connectable See here.
Specify the schema (if database flavor supports this). If None, use default schema.
How to behave if the table already exists.
fail: Raise a ValueError.
replace: Drop the table before inserting new values.
append: Insert new values to the existing table.
Write DataFrame index as a column. Uses index_label as the column name in the table.
Column label for index column(s). If None is given (default) and index is True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex.
Specify the number of rows in each batch to be written at a time. By default, all rows will be written at once.
Specifying the datatype for columns. If a dictionary is used, the keys should be the column names and the values should be the SQLAlchemy types or strings for the sqlite3 legacy mode. If a scalar is provided, it will be applied to all columns.
Controls the SQL insertion clause used:
None : Uses standard SQL INSERT clause (one per row).
‘multi’: Pass multiple values in a single INSERT clause.
callable with signature (pd_table, conn, keys, data_iter).
Details and a sample callable implementation can be found in the section insert method.
Number of rows affected by to_sql. None is returned if the callable passed into method does not return the number of rows.
The number of returned rows affected is the sum of the rowcount attribute of sqlite3.Cursor or SQLAlchemy connectable which may not reflect the exact number of written rows as stipulated in the sqlite3 or SQLAlchemy.
New in version 1.4.0.
When the table already exists and if_exists is ‘fail’ (the default).
See also
Read a DataFrame from a table.
Notes
Timezone aware datetime columns will be written as Timestamp with timezone type with SQLAlchemy if supported by the database. Otherwise, the datetimes will be stored as timezone unaware timestamps local to the original timezone.
References
https://docs.sqlalchemy.org
https://www.python.org/dev/peps/pep-0249/
Examples
Create an in-memory SQLite database.
Create a table from scratch with 3 rows.
An sqlalchemy.engine.Connection can also be passed to con:
This is allowed to support operations that require that the same DBAPI connection is used for the entire operation.
Overwrite the table with just df2.
Specify the dtype (especially useful for integers with missing values). Notice that while pandas is forced to store the data as floating point, the database supports nullable integers. When fetching the data with Python, we get back integer scalars.


Export DataFrame object to Stata dta format.
Writes the DataFrame to a Stata dataset file. “dta” files contain a Stata dataset.
String, path object (implementing os.PathLike[str]), or file-like object implementing a binary write() function.
Changed in version 1.0.0.
Previously this was “fname”
Dictionary mapping columns containing datetime types to stata internal format to use when writing the dates. Options are ‘tc’, ‘td’, ‘tm’, ‘tw’, ‘th’, ‘tq’, ‘ty’. Column can be either an integer or a name. Datetime columns that do not have a conversion type specified will be converted to ‘tc’. Raises NotImplementedError if a datetime column has timezone information.
Write the index to Stata dataset.
Can be “>”, “<”, “little”, or “big”. default is sys.byteorder.
A datetime to use as file creation date. Default is the current time.
A label for the data set. Must be 80 characters or smaller.
Dictionary containing columns as keys and variable labels as values. Each label must be 80 characters or smaller.
Version to use in the output dta file. Set to None to let pandas decide between 118 or 119 formats depending on the number of columns in the frame. Version 114 can be read by Stata 10 and later. Version 117 can be read by Stata 13 or later. Version 118 is supported in Stata 14 and later. Version 119 is supported in Stata 15 and later. Version 114 limits string variables to 244 characters or fewer while versions 117 and later allow strings with lengths up to 2,000,000 characters. Versions 118 and 119 support Unicode characters, and version 119 supports more than 32,767 variables.
Version 119 should usually only be used when the number of variables exceeds the capacity of dta format 118. Exporting smaller datasets in format 119 may have unintended consequences, and, as of November 2020, Stata SE cannot read version 119 files.
Changed in version 1.0.0: Added support for formats 118 and 119.
List of column names to convert to string columns to Stata StrL format. Only available if version is 117. Storing strings in the StrL format can produce smaller dta files if strings have more than 8 characters and values are repeated.
For on-the-fly compression of the output data. If ‘infer’ and ‘path’ path-like, then detect compression from the following extensions: ‘.gz’, ‘.bz2’, ‘.zip’, ‘.xz’, or ‘.zst’ (otherwise no compression). Set to None for no compression. Can also be a dict with key 'method' set to one of {'zip', 'gzip', 'bz2', 'zstd'} and other key-value pairs are forwarded to zipfile.ZipFile, gzip.GzipFile, bz2.BZ2File, or zstandard.ZstdDecompressor, respectively. As an example, the following could be passed for faster compression and to create a reproducible gzip archive: compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}.
New in version 1.1.0.
Changed in version 1.4.0: Zstandard support.
Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec. Please see fsspec and urllib for more details.
New in version 1.2.0.
Dictionary containing columns as keys and dictionaries of column value to labels as values. Labels for a single variable must be 32,000 characters or smaller.
New in version 1.4.0.
If datetimes contain timezone information
Column dtype is not representable in Stata
Columns listed in convert_dates are neither datetime64[ns] or datetime.datetime
Column listed in convert_dates is not in DataFrame
Categorical label contains more than 32,000 characters
See also
Import Stata data files.
Low-level writer for Stata data files.
Low-level writer for version 117 files.
Examples


Render a DataFrame to a console-friendly tabular output.
Buffer to write to. If None, the output is returned as a string.
The subset of columns to write. Writes all columns by default.
The minimum width of each column. If a list of ints is given every integers corresponds with one column. If a dict is given, the key references the column, while the value defines the space to use..
Write out the column names. If a list of strings is given, it is assumed to be aliases for the column names.
Whether to print index (row) labels.
String representation of NaN to use.
Formatter functions to apply to columns’ elements by position or name. The result of each function must be a unicode string. List/tuple must be of length equal to the number of columns.
Formatter function to apply to columns’ elements if they are floats. This function must return a unicode string and will be applied only to the non-NaN elements, with NaN being handled by na_rep.
Changed in version 1.2.0.
Set to False for a DataFrame with a hierarchical index to print every multiindex key at each row.
Prints the names of the indexes.
How to justify the column labels. If None uses the option from the print configuration (controlled by set_option), ‘right’ out of the box. Valid values are
left
right
center
justify
justify-all
start
end
inherit
match-parent
initial
unset.
Maximum number of rows to display in the console.
Maximum number of columns to display in the console.
Display DataFrame dimensions (number of rows by number of columns).
Character recognized as decimal separator, e.g. ‘,’ in Europe.
Width to wrap a line in characters.
The number of rows to display in the console in a truncated repr (when number of rows is above max_rows).
Max width to truncate each column in characters. By default, no limit.
New in version 1.0.0.
Set character encoding.
New in version 1.0.
If buf is None, returns the result as a string. Otherwise returns None.
See also
Convert DataFrame to HTML.
Examples


Cast to DatetimeIndex of timestamps, at beginning of period.
Desired frequency.
Convention for converting period to timestamp; start of period vs. end.
The axis to convert (the index by default).
If False then underlying input data is not copied.


Return an xarray object from the pandas object.
Data in the pandas structure converted to Dataset if the object is a DataFrame, or a DataArray if the object is a Series.
See also
Write DataFrame to an HDF5 file.
Write a DataFrame to the binary parquet format.
Notes
See the xarray docs
Examples


Render a DataFrame to an XML document.
New in version 1.3.0.
String, path object (implementing os.PathLike[str]), or file-like object implementing a write() function. If None, the result is returned as a string.
Whether to include index in XML document.
The name of root element in XML document.
The name of row element in XML document.
Missing data representation.
List of columns to write as attributes in row element. Hierarchical columns will be flattened with underscore delimiting the different levels.
List of columns to write as children in row element. By default, all columns output as children of row element. Hierarchical columns will be flattened with underscore delimiting the different levels.
All namespaces to be defined in root element. Keys of dict should be prefix names and values of dict corresponding URIs. Default namespaces should be given empty string key. For example,
Namespace prefix to be used for every element and/or attribute in document. This should be one of the keys in namespaces dict.
Encoding of the resulting document.
Whether to include the XML declaration at start of document.
Whether output should be pretty printed with indentation and line breaks.
Parser module to use for building of tree. Only ‘lxml’ and ‘etree’ are supported. With ‘lxml’, the ability to use XSLT stylesheet is supported.
A URL, file-like object, or a raw string containing an XSLT script used to transform the raw XML output. Script should use layout of elements and attributes from original output. This argument requires lxml to be installed. Only XSLT 1.0 scripts and not later versions is currently supported.
For on-the-fly compression of the output data. If ‘infer’ and ‘path_or_buffer’ path-like, then detect compression from the following extensions: ‘.gz’, ‘.bz2’, ‘.zip’, ‘.xz’, or ‘.zst’ (otherwise no compression). Set to None for no compression. Can also be a dict with key 'method' set to one of {'zip', 'gzip', 'bz2', 'zstd'} and other key-value pairs are forwarded to zipfile.ZipFile, gzip.GzipFile, bz2.BZ2File, or zstandard.ZstdDecompressor, respectively. As an example, the following could be passed for faster compression and to create a reproducible gzip archive: compression={'method': 'gzip', 'compresslevel': 1, 'mtime': 1}.
Changed in version 1.4.0: Zstandard support.
Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with “s3://”, and “gcs://”) the key-value pairs are forwarded to fsspec. Please see fsspec and urllib for more details.
If io is None, returns the resulting XML format as a string. Otherwise returns None.
See also
Convert the pandas object to a JSON string.
Convert DataFrame to a html.
Examples


Call func on self producing a DataFrame with the same axis shape as self.
Function to use for transforming the data. If a function, must either work when passed a DataFrame or when passed to DataFrame.apply. If func is both list-like and dict-like, dict-like behavior takes precedence.
Accepted combinations are:
function
string function name
list-like of functions and/or function names, e.g. [np.exp, 'sqrt']
dict-like of axis labels -> functions, function names or list-like of such.
If 0 or ‘index’: apply function to each column. If 1 or ‘columns’: apply function to each row.
Positional arguments to pass to func.
Keyword arguments to pass to func.
A DataFrame that must have the same length as self.
See also
Only perform aggregating type operations.
Invoke function on a DataFrame.
Notes
Functions that mutate the passed object can produce unexpected behavior or errors and are not supported. See Mutating with User Defined Function (UDF) methods for more details.
Examples
Even though the resulting DataFrame must have the same length as the input DataFrame, it is possible to provide several input functions:
You can call transform on a GroupBy object:


Transpose index and columns.
Reflect the DataFrame over its main diagonal by writing rows as columns and vice-versa. The property T is an accessor to the method transpose().
Accepted for compatibility with NumPy.
Whether to copy the data after transposing, even for DataFrames with a single dtype.
Note that a copy is always required for mixed dtype DataFrames, or for DataFrames with any extension types.
The transposed DataFrame.
See also
Permute the dimensions of a given array.
Notes
Transposing a DataFrame with mixed dtypes will result in a homogeneous DataFrame with the object dtype. In such a case, a copy of the data is always made.
Examples
Square DataFrame with homogeneous dtype
When the dtype is homogeneous in the original DataFrame, we get a transposed DataFrame with the same dtype:
Non-square DataFrame with mixed dtypes
When the DataFrame has mixed dtypes, we get a transposed DataFrame with the object dtype:


Get Floating division of dataframe and other, element-wise (binary operator truediv).
Equivalent to dataframe / other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rtruediv.
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.


Truncate a Series or DataFrame before and after some index value.
This is a useful shorthand for boolean indexing based on index values above or below certain thresholds.
Truncate all rows before this index value.
Truncate all rows after this index value.
Axis to truncate. Truncates the index (rows) by default.
Return a copy of the truncated section.
The truncated Series or DataFrame.
See also
Select a subset of a DataFrame by label.
Select a subset of a DataFrame by position.
Notes
If the index being truncated contains only datetime values, before and after may be specified as strings instead of Timestamps.
Examples
The columns of a DataFrame can be truncated.
For Series, only rows can be truncated.
The index values in truncate can be datetimes or string dates.
Because the index is a DatetimeIndex containing only dates, we can specify before and after as strings. They will be coerced to Timestamps before truncation.
Note that truncate assumes a 0 value for any unspecified time component (midnight). This differs from partial string slicing, which returns any partially matching dates.


Shift the time index, using the index’s frequency if available.
Deprecated since version 1.1.0: Use shift instead.
Number of periods to move, can be positive or negative.
Increment to use from the tseries module or time rule expressed as a string (e.g. ‘EOM’).
Corresponds to the axis that contains the Index.
Notes
If freq is not specified then tries to use the freq or inferred_freq attributes of the index. If neither of those attributes exist, a ValueError is thrown


Convert tz-aware axis to target time zone.
If axis is a MultiIndex, convert a specific level. Otherwise must be None.
Also make a copy of the underlying data.
Object with time zone converted axis.
If the axis is tz-naive.


Localize tz-naive index of a Series or DataFrame to target time zone.
This operation localizes the Index. To localize the values in a timezone-naive Series, use Series.dt.tz_localize().
If axis ia a MultiIndex, localize a specific level. Otherwise must be None.
Also make a copy of the underlying data.
When clocks moved backward due to DST, ambiguous times may arise. For example in Central European Time (UTC+01), when going from 03:00 DST to 02:00 non-DST, 02:30:00 local time occurs both at 00:30:00 UTC and at 01:30:00 UTC. In such a situation, the ambiguous parameter dictates how ambiguous times should be handled.
‘infer’ will attempt to infer fall dst-transition hours based on order
bool-ndarray where True signifies a DST time, False designates a non-DST time (note that this flag is only applicable for ambiguous times)
‘NaT’ will return NaT where there are ambiguous times
‘raise’ will raise an AmbiguousTimeError if there are ambiguous times.
A nonexistent time does not exist in a particular timezone where clocks moved forward due to DST. Valid values are:
‘shift_forward’ will shift the nonexistent time forward to the closest existing time
‘shift_backward’ will shift the nonexistent time backward to the closest existing time
‘NaT’ will return NaT where there are nonexistent times
timedelta objects will shift nonexistent times by the timedelta
‘raise’ will raise an NonExistentTimeError if there are nonexistent times.
Same type as the input.
If the TimeSeries is tz-aware and tz is not None.
Examples
Localize local times:
Be careful with DST changes. When there is sequential data, pandas can infer the DST time:
In some cases, inferring the DST is impossible. In such cases, you can pass an ndarray to the ambiguous parameter to set the DST explicitly
If the DST transition causes nonexistent times, you can shift these dates forward or backward with a timedelta object or ‘shift_forward’ or ‘shift_backward’.


Pivot a level of the (necessarily hierarchical) index labels.
Returns a DataFrame having a new level of column labels whose inner-most level consists of the pivoted index labels.
If the index is not a MultiIndex, the output will be a Series (the analogue of stack when the columns are not a MultiIndex).
Level(s) of index to unstack, can pass level name.
Replace NaN with this value if the unstack produces missing values.
See also
Pivot a table based on column values.
Pivot a level of the column labels (inverse operation from unstack).
Examples


Modify in place using non-NA values from another DataFrame.
Aligns on indices. There is no return value.
Should have at least one matching index/column label with the original DataFrame. If a Series is passed, its name attribute must be set, and that will be used as the column name to align with the original DataFrame.
Only left join is implemented, keeping the index and columns of the original object.
How to handle non-NA values for overlapping keys:
True: overwrite original DataFrame’s values with values from other.
False: only update values that are NA in the original DataFrame.
Can choose to replace values other than NA. Return True for values that should be updated.
If ‘raise’, will raise a ValueError if the DataFrame and other both contain non-NA data in the same place.
When errors=’raise’ and there’s overlapping non-NA data.
When errors is not either ‘ignore’ or ‘raise’
If join != ‘left’
See also
Similar method for dictionaries.
For column(s)-on-column(s) operations.
Examples
The DataFrame’s length does not increase as a result of the update, only values at matching index/column labels are updated.
For Series, its name attribute must be set.
If other contains NaNs the corresponding values are not updated in the original dataframe.


Return a Series containing counts of unique rows in the DataFrame.
New in version 1.1.0.
Columns to use when counting unique combinations.
Return proportions rather than frequencies.
Sort by frequencies.
Sort in ascending order.
Don’t include counts of rows that contain NA values.
New in version 1.3.0.
See also
Equivalent method on Series.
Notes
The returned Series will have a MultiIndex with one level per input column. By default, rows that contain any NA values are omitted from the result. By default, the resulting Series will be in descending order so that the first element is the most frequently-occurring row.
Examples
With dropna set to False we can also count rows with NA values.


Return a Numpy representation of the DataFrame.
Warning
We recommend using DataFrame.to_numpy() instead.
Only the values in the DataFrame will be returned, the axes labels will be removed.
The values of the DataFrame.
See also
Recommended alternative to this method.
Retrieve the index labels.
Retrieving the column names.
Notes
The dtype will be a lower-common-denominator dtype (implicit upcasting); that is to say if the dtypes (even of numeric types) are mixed, the one that accommodates all will be chosen. Use this with care if you are not dealing with the blocks.
e.g. If the dtypes are float16 and float32, dtype will be upcast to float32. If dtypes are int32 and uint8, dtype will be upcast to int32. By numpy.find_common_type() convention, mixing int64 and uint64 will result in a float64 dtype.
Examples
A DataFrame where all columns are the same type (e.g., int64) results in an array of the same type.
A DataFrame with mixed type columns(e.g., str/object, int64, float32) results in an ndarray of the broadest type that accommodates these mixed types (e.g., object).


Return unbiased variance over requested axis.
Normalized by N-1 by default. This can be changed using the ddof argument.
Exclude NA/null values. If an entire row/column is NA, the result will be NA.
If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.
Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements.
Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
Examples
Alternatively, ddof=0 can be set to normalize by N instead of N-1:


Replace values where the condition is False.
Where cond is True, keep the original value. Where False, 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 False 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 where method is an application of the if-then idiom. For each element in the calling DataFrame, if cond is True 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 where documentation in indexing.
Examples


Return cross-section from the Series/DataFrame.
This method takes a key argument to select data at a particular level of a MultiIndex.
Label contained in the index, or partially in a MultiIndex.
Axis to retrieve cross-section on.
In case of a key partially contained in a MultiIndex, indicate which levels are used. Levels can be referred by label or position.
If False, returns object with same levels as self.
Cross-section from the original Series or DataFrame corresponding to the selected index levels.
See also
Access a group of rows and columns by label(s) or a boolean array.
Purely integer-location based indexing for selection by position.
Notes
xs can not be used to set values.
MultiIndex Slicers is a generic way to get/set values on any level or levels. It is a superset of xs functionality, see MultiIndex Slicers.
Examples
Get values at specified index
Get values at several indexes
Get values at specified index and level
Get values at several indexes and levels
Get values at specified column and axis


Return a fixed frequency DatetimeIndex.
Returns the range of equally spaced time points (where the difference between any two adjacent points is specified by the given frequency) such that they all satisfy start <[=] x <[=] end, where the first one and the last one are, resp., the first and last time points in that range that fall on the boundary of freq (if given as a frequency string) or that are valid for freq (if given as a pandas.tseries.offsets.DateOffset). (If exactly one of start, end, or freq is not specified, this missing parameter can be computed given periods, the number of timesteps in the range. See the note below.)
Left bound for generating dates.
Right bound for generating dates.
Number of periods to generate.
Frequency strings can have multiples, e.g. ‘5H’. See here for a list of frequency aliases.
Time zone name for returning localized DatetimeIndex, for example ‘Asia/Hong_Kong’. By default, the resulting DatetimeIndex is timezone-naive.
Normalize start/end dates to midnight before generating date range.
Name of the resulting DatetimeIndex.
Make the interval closed with respect to the given frequency to the ‘left’, ‘right’, or both sides (None, the default).
Deprecated since version 1.4.0: Argument closed has been deprecated to standardize boundary inputs. Use inclusive instead, to set each bound as closed or open.
Include boundaries; Whether to set each bound as closed or open.
New in version 1.4.0.
For compatibility. Has no effect on the result.
See also
An immutable container for datetimes.
Return a fixed frequency TimedeltaIndex.
Return a fixed frequency PeriodIndex.
Return a fixed frequency IntervalIndex.
Notes
Of the four parameters start, end, periods, and freq, exactly three must be specified. If freq is omitted, the resulting DatetimeIndex will have periods linearly spaced elements between start and end (closed on both sides).
To learn more about the frequency strings, please see this link.
Examples
Specifying the values
The next four examples generate the same DatetimeIndex, but vary the combination of start, end and periods.
Specify start and end, with the default daily frequency.
Specify start and periods, the number of periods (days).
Specify end and periods, the number of periods (days).
Specify start, end, and periods; the frequency is generated automatically (linearly spaced).
Other Parameters
Changed the freq (frequency) to 'M' (month end frequency).
Multiples are allowed
freq can also be specified as an Offset object.
Specify tz to set the timezone.
inclusive controls whether to include start and end that are on the boundary. The default, “both”, includes boundary points on either end.
Use inclusive='left' to exclude end if it falls on the boundary.
Use inclusive='right' to exclude start if it falls on the boundary, and similarly inclusive='neither' will exclude both start and end.


Immutable ndarray-like of datetime64 data.
Represented internally as int64, and which can be boxed to Timestamp objects that are subclasses of datetime and carry metadata.
Optional datetime-like data to construct index with.
One of pandas date offset strings or corresponding objects. The string ‘infer’ can be passed in order to set the frequency of the index as the inferred frequency upon creation.
Set the Timezone of the data.
Normalize start/end dates to midnight before generating date range.
Set whether to include start and end that are on the boundary. The default includes boundary points on either end.
When clocks moved backward due to DST, ambiguous times may arise. For example in Central European Time (UTC+01), when going from 03:00 DST to 02:00 non-DST, 02:30:00 local time occurs both at 00:30:00 UTC and at 01:30:00 UTC. In such a situation, the ambiguous parameter dictates how ambiguous times should be handled.
‘infer’ will attempt to infer fall dst-transition hours based on order
bool-ndarray where True signifies a DST time, False signifies a non-DST time (note that this flag is only applicable for ambiguous times)
‘NaT’ will return NaT where there are ambiguous times
‘raise’ will raise an AmbiguousTimeError if there are ambiguous times.
If True, parse dates in data with the day first order.
If True parse dates in data with the year first order.
Note that the only NumPy dtype allowed is ‘datetime64[ns]’.
Make a copy of input ndarray.
Name to be stored in the index.
See also
The base pandas Index type.
Index of timedelta64 data.
Index of Period data.
Convert argument to datetime.
Create a fixed-frequency DatetimeIndex.
Notes
To learn more about the frequency strings, please see this link.
Attributes
year
The year of the datetime.
month
The month as January=1, December=12.
day
The day of the datetime.
hour
The hours of the datetime.
minute
The minutes of the datetime.
second
The seconds of the datetime.
microsecond
The microseconds of the datetime.
nanosecond
The nanoseconds of the datetime.
date
Returns numpy array of python datetime.date objects.
time
Returns numpy array of datetime.time objects.
timetz
Returns numpy array of datetime.time objects with timezone information.
dayofyear
The ordinal day of the year.
day_of_year
The ordinal day of the year.
weekofyear
(DEPRECATED) The week ordinal of the year.
week
(DEPRECATED) The week ordinal of the year.
dayofweek
The day of the week with Monday=0, Sunday=6.
day_of_week
The day of the week with Monday=0, Sunday=6.
weekday
The day of the week with Monday=0, Sunday=6.
quarter
The quarter of the date.
tz
Return the timezone.
freq
Return the frequency object if it is set, otherwise None.
freqstr
Return the frequency object as a string if its set, otherwise None.
is_month_start
Indicates whether the date is the first day of the month.
is_month_end
Indicates whether the date is the last day of the month.
is_quarter_start
Indicator for whether the date is the first day of a quarter.
is_quarter_end
Indicator for whether the date is the last day of a quarter.
is_year_start
Indicate whether the date is the first day of a year.
is_year_end
Indicate whether the date is the last day of the year.
is_leap_year
Boolean indicator if the date belongs to a leap year.
inferred_freq
Tries to return a string representing a frequency guess, generated by infer_freq.
Methods
normalize(*args, **kwargs)
Convert times to midnight.
strftime(*args, **kwargs)
Convert to Index using specified date_format.
snap([freq])
Snap time stamps to nearest occurring frequency.
tz_convert(tz)
Convert tz-aware Datetime Array/Index from one time zone to another.
tz_localize(tz[, ambiguous, nonexistent])
Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index.
round(*args, **kwargs)
Perform round operation on the data to the specified freq.
floor(*args, **kwargs)
Perform floor operation on the data to the specified freq.
ceil(*args, **kwargs)
Perform ceil operation on the data to the specified freq.
to_period(*args, **kwargs)
Cast to PeriodArray/Index at a particular frequency.
to_perioddelta(freq)
Calculate TimedeltaArray of difference between index values and index converted to PeriodArray at specified freq.
to_pydatetime(*args, **kwargs)
Return Datetime Array/Index as object ndarray of datetime.datetime objects.
to_series([keep_tz, index, name])
Create a Series with both index and values equal to the index keys useful with map for returning an indexer based on an index.
to_frame([index, name])
Create a DataFrame with a column containing the Index.
month_name(*args, **kwargs)
Return the month names of the DateTimeIndex with specified locale.
day_name(*args, **kwargs)
Return the day names of the DateTimeIndex with specified locale.
mean(*args, **kwargs)
Return the mean value of the Array.
std(*args, **kwargs)
Return sample standard deviation over requested axis.


Perform ceil operation on the data to the specified freq.
The frequency level to ceil the index to. Must be a fixed frequency like ‘S’ (second) not ‘ME’ (month end). See frequency aliases for a list of possible freq values.
Only relevant for DatetimeIndex:
‘infer’ will attempt to infer fall dst-transition hours based on order
bool-ndarray where True signifies a DST time, False designates a non-DST time (note that this flag is only applicable for ambiguous times)
‘NaT’ will return NaT where there are ambiguous times
‘raise’ will raise an AmbiguousTimeError if there are ambiguous times.
A nonexistent time does not exist in a particular timezone where clocks moved forward due to DST.
‘shift_forward’ will shift the nonexistent time forward to the closest existing time
‘shift_backward’ will shift the nonexistent time backward to the closest existing time
‘NaT’ will return NaT where there are nonexistent times
timedelta objects will shift nonexistent times by the timedelta
‘raise’ will raise an NonExistentTimeError if there are nonexistent times.
Index of the same type for a DatetimeIndex or TimedeltaIndex, or a Series with the same index for a Series.
Notes
If the timestamps have a timezone, ceiling will take place relative to the local (“wall”) time and re-localized to the same timezone. When ceiling near daylight savings time, use nonexistent and ambiguous to control the re-localization behavior.
Examples
DatetimeIndex
Series
When rounding near a daylight savings time transition, use ambiguous or nonexistent to control how the timestamp should be re-localized.


Returns numpy array of python datetime.date objects.
Namely, the date part of Timestamps without time and timezone information.


Return the day names of the DateTimeIndex with specified locale.
Locale determining the language in which to return the day name. Default is English locale.
Index of day names.
Examples


The day of the week with Monday=0, Sunday=6.
Return the day of the week. It is assumed the week starts on Monday, which is denoted by 0 and ends on Sunday which is denoted by 6. This method is available on both Series with datetime values (using the dt accessor) or DatetimeIndex.
Containing integers indicating the day number.
See also
Alias.
Alias.
Returns the name of the day of the week.
Examples