API Reference

DataFrame

class cudf.core.dataframe.DataFrame(data=None, index=None, columns=None, dtype=None)

A GPU Dataframe object.

Parameters
dataarray-like, Iterable, dict, or DataFrame.

Dict can contain Series, arrays, constants, or list-like objects.

indexIndex or array-like

Index to use for resulting frame. Will default to RangeIndex if no indexing information part of input data and no index provided.

columnsIndex or array-like

Column labels to use for resulting frame. Will default to RangeIndex (0, 1, 2, …, n) if no column labels are provided.

dtypedtype, default None

Data type to force. Only a single dtype is allowed. If None, infer.

Examples

Build dataframe with __setitem__:

>>> import cudf
>>> df = cudf.DataFrame()
>>> df['key'] = [0, 1, 2, 3, 4]
>>> df['val'] = [float(i + 10) for i in range(5)]  # insert column
>>> print(df)
key   val
0    0  10.0
1    1  11.0
2    2  12.0
3    3  13.0
4    4  14.0

Build DataFrame via dict of columns:

>>> import cudf
>>> import numpy as np
>>> from datetime import datetime, timedelta
>>> t0 = datetime.strptime('2018-10-07 12:00:00', '%Y-%m-%d %H:%M:%S')
>>> n = 5
>>> df = cudf.DataFrame({
>>> 'id': np.arange(n),
>>> 'datetimes': np.array(
>>> [(t0+ timedelta(seconds=x)) for x in range(n)])
>>> })
>>> df
    id                datetimes
0    0  2018-10-07T12:00:00.000
1    1  2018-10-07T12:00:01.000
2    2  2018-10-07T12:00:02.000
3    3  2018-10-07T12:00:03.000
4    4  2018-10-07T12:00:04.000

Build DataFrame via list of rows as tuples:

>>> import cudf
>>> df = cudf.DataFrame([
    (5, "cats", "jump", np.nan),
    (2, "dogs", "dig", 7.5),
    (3, "cows", "moo", -2.1, "occasionally"),
])
>>> df
0     1     2     3             4
0  5  cats  jump  null          None
1  2  dogs   dig   7.5          None
2  3  cows   moo  -2.1  occasionally

Convert from a Pandas DataFrame:

>>> import pandas as pd
>>> import cudf
>>> pdf = pd.DataFrame({'a': [0, 1, 2, 3],'b': [0.1, 0.2, None, 0.3]})
>>> df = cudf.from_pandas(pdf)
>>> df
a b
0 0 0.1
1 1 0.2
2 2 nan
3 3 0.3
Attributes
T

Transpose index and columns.

at

Alias for DataFrame.loc; provided for compatibility with Pandas.

columns

Returns a tuple of columns

dtypes

Return the dtypes in this object.

empty

Indicator whether DataFrame is empty.

iat

Alias for DataFrame.iloc; provided for compatibility with Pandas.

iloc

Selecting rows and column by position.

index

Returns the index of the DataFrame

loc

Selecting rows and columns by label or boolean mask.

ndim

Dimension of the data.

shape

Returns a tuple representing the dimensionality of the DataFrame.

values

Return a CuPy representation of the DataFrame.

Methods

add(self, other[, axis, level, fill_value])

Get Addition of dataframe and other, element-wise (binary operator add).

add_column(self, name, data[, forceindex])

Add a column

all(self[, axis, bool_only, skipna, level])

Return whether all elements are True in DataFrame.

any(self[, axis, bool_only, skipna, level])

Return whether any elements is True in DataFrame.

apply_chunks(self, func, incols, outcols[, …])

Transform user-specified chunks using the user-provided function.

apply_rows(self, func, incols, outcols, kwargs)

Apply a row-wise user defined function.

argsort(self[, ascending, na_position])

Sort by the values.

as_gpu_matrix(self[, columns, order])

Convert to a matrix in device memory.

as_matrix(self[, columns])

Convert to a matrix in host memory.

assign(self, **kwargs)

Assign columns to DataFrame from keyword arguments.

astype(self, dtype[, copy, errors])

Cast the DataFrame to the given dtype

copy(self[, deep])

Returns a copy of this dataframe

corr(self)

Compute the correlation matrix of a DataFrame.

count(self[, axis, level, numeric_only])

Count non-NA cells for each column or row.

cov(self, **kwargs)

Compute the covariance matrix of a DataFrame.

cummax(self[, axis, skipna])

Return cumulative maximum of the DataFrame.

cummin(self[, axis, skipna])

Return cumulative minimum of the DataFrame.

cumprod(self[, axis, skipna])

Return cumulative product of the DataFrame.

cumsum(self[, axis, skipna])

Return cumulative sum of the DataFrame.

describe(self[, percentiles, include, exclude])

Compute summary statistics of a DataFrame’s columns.

div(self, other[, axis, level, fill_value])

Get Floating division of dataframe and other, element-wise (binary operator truediv).

drop(self[, labels, axis, columns, errors, …])

Drop column(s)

drop_column(self, name)

Drop a column by name

drop_duplicates(self[, subset, keep, …])

Return DataFrame with duplicate rows removed, optionally only considering certain subset of columns.

equals(self, other)

Test whether two objects contain the same elements.

fillna(self, value[, method, axis, inplace, …])

Fill null values with value.

floordiv(self, other[, axis, level, fill_value])

Get Integer division of dataframe and other, element-wise (binary operator floordiv).

from_arrow(table)

Convert from a PyArrow Table.

from_gpu_matrix(data[, index, columns, …])

Convert from a numba gpu ndarray.

from_pandas(dataframe[, nan_as_null])

Convert from a Pandas DataFrame.

from_records(data[, index, columns, nan_as_null])

Convert structured or record ndarray to DataFrame.

groupby(self[, by, axis, level, as_index, …])

Group DataFrame using a mapper or by a Series of columns.

hash_columns(self[, columns])

Hash the given columns and return a new device array

head(self[, n])

Returns the first n rows as a new DataFrame

info(self[, verbose, buf, max_cols, …])

Print a concise summary of a DataFrame.

insert(self, loc, name, value)

Add a column to DataFrame at the index specified by loc.

isin(self, values)

Whether each element in the DataFrame is contained in values.

iteritems(self)

Iterate over column names and series pairs

join(self, other[, on, how, lsuffix, …])

Join columns with other DataFrame on index or on a key column.

kurt(self[, axis, skipna, level, numeric_only])

Return Fisher’s unbiased kurtosis of a sample.

kurtosis(self[, axis, skipna, level, …])

Return Fisher’s unbiased kurtosis of a sample.

label_encoding(self, column, prefix, cats[, …])

Encode labels in a column with label encoding.

max(self[, axis, skipna, dtype, level, …])

Return the maximum of the values in the DataFrame.

mean(self[, axis, skipna, level, numeric_only])

Return the mean of the values for the requested axis.

melt(self, **kwargs)

Unpivots a DataFrame from wide format to long format, optionally leaving identifier variables set.

memory_usage(self[, index, deep])

Return the memory usage of each column in bytes.

merge(self, right[, on, left_on, right_on, …])

Merge GPU DataFrame objects by performing a database-style join operation by columns or indexes.

min(self[, axis, skipna, dtype, level, …])

Return the minimum of the values in the DataFrame.

mod(self, other[, axis, level, fill_value])

Get Modulo division of dataframe and other, element-wise (binary operator mod).

mul(self, other[, axis, level, fill_value])

Get Multiplication of dataframe and other, element-wise (binary operator mul).

nans_to_nulls(self)

Convert nans (if any) to nulls.

nlargest(self, n, columns[, keep])

Get the rows of the DataFrame sorted by the n largest value of columns

nsmallest(self, n, columns[, keep])

Get the rows of the DataFrame sorted by the n smallest value of columns

one_hot_encoding(self, column, prefix, cats)

Expand a column with one-hot-encoding.

partition_by_hash(self, columns, nparts[, …])

Partition the dataframe by the hashed value of data in columns.

pop(self, item)

Return a column and drop it from the DataFrame.

pow(self, other[, axis, level, fill_value])

Get Exponential power of dataframe and other, element-wise (binary operator pow).

prod(self[, axis, skipna, dtype, level, …])

Return product of the values in the DataFrame.

product(self[, axis, skipna, dtype, level, …])

Return product of the values in the DataFrame.

quantile(self[, q, axis, numeric_only, …])

Return values at the given quantile.

quantiles(self[, q, interpolation])

Return values at the given quantile.

query(self, expr[, local_dict])

Query with a boolean expression using Numba to compile a GPU kernel.

radd(self, other[, axis, level, fill_value])

Get Addition of dataframe and other, element-wise (binary operator radd).

rdiv(self, other[, axis, level, fill_value])

Get Floating division of dataframe and other, element-wise (binary operator rtruediv).

reindex(self[, labels, axis, index, …])

Return a new DataFrame whose axes conform to a new index

rename(self[, mapper, index, columns, axis, …])

Alter column and index labels.

replace(self[, to_replace, value, inplace, …])

Replace values given in to_replace with replacement.

reset_index(self[, level, drop, inplace, …])

Reset the index.

rfloordiv(self, other[, axis, level, fill_value])

Get Integer division of dataframe and other, element-wise (binary operator rfloordiv).

rmod(self, other[, axis, level, fill_value])

Get Modulo division of dataframe and other, element-wise (binary operator rmod).

rmul(self, other[, axis, level, fill_value])

Get Multiplication of dataframe and other, element-wise (binary operator rmul).

rolling(self, window[, min_periods, center, …])

Rolling window calculations.

rpow(self, other[, axis, level, fill_value])

Get Exponential power of dataframe and other, element-wise (binary operator pow).

rsub(self, other[, axis, level, fill_value])

Get Subtraction of dataframe and other, element-wise (binary operator rsub).

rtruediv(self, other[, axis, level, fill_value])

Get Floating division of dataframe and other, element-wise (binary operator rtruediv).

select_dtypes(self[, include, exclude])

Return a subset of the DataFrame’s columns based on the column dtypes.

set_index(self, index[, drop])

Return a new DataFrame with a new index

skew(self[, axis, skipna, level, numeric_only])

Return unbiased Fisher-Pearson skew of a sample.

sort_index(self[, axis, level, ascending, …])

Sort object by labels (along an axis).

sort_values(self, by[, axis, ascending, …])

Sort by the values row-wise.

stack(self[, level, dropna])

Stack the prescribed level(s) from columns to index

std(self[, axis, skipna, level, ddof, …])

Return sample standard deviation of the DataFrame.

sub(self, other[, axis, level, fill_value])

Get Subtraction of dataframe and other, element-wise (binary operator sub).

sum(self[, axis, skipna, dtype, level, …])

Return sum of the values in the DataFrame.

tail(self[, n])

Returns the last n rows as a new DataFrame

take(self, positions[, keep_index])

Return a new DataFrame containing the rows specified by positions

to_arrow(self[, preserve_index])

Convert to a PyArrow Table.

to_csv(self[, path, sep, na_rep, columns, …])

Write a dataframe to csv file format.

to_dlpack(self)

Converts a cuDF object into a DLPack tensor.

to_feather(self, path, *args, **kwargs)

Write a DataFrame to the feather format.

to_gpu_matrix(self)

Convert to a numba gpu ndarray

to_hdf(self, path_or_buf, key, *args, **kwargs)

Write the contained data to an HDF5 file using HDFStore.

to_json(self[, path_or_buf])

Convert the cuDF object to a JSON string.

to_orc(self, fname[, compression])

Write a DataFrame to the ORC format.

to_pandas(self)

Convert to a Pandas DataFrame.

to_parquet(self, path, *args, **kwargs)

Write a DataFrame to the parquet format.

to_records(self[, index])

Convert to a numpy recarray

to_string(self)

Convert to string

transpose(self)

Transpose index and columns.

truediv(self, other[, axis, level, fill_value])

Get Floating division of dataframe and other, element-wise (binary operator truediv).

var(self[, axis, skipna, level, ddof, …])

Return unbiased variance of the DataFrame.

property T

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().

Returns
outDataFrame

The transposed DataFrame.

add(self, other, axis='columns', level=None, fill_value=None)

Get Addition of dataframe and other, element-wise (binary operator add).

Equivalent to dataframe + other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, radd.

Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df + 1
        angles  degrees
circle          1      361
triangle        4      181
rectangle       5      361
>>> df.add(1)
        angles  degrees
circle          1      361
triangle        4      181
rectangle       5      361
add_column(self, name, data, forceindex=False)

Add a column

Parameters
namestr

Name of column to be added.

dataSeries, array-like

Values to be added.

all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs)

Return whether all elements are True in DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values. If the entire row/column is NA and skipna is True, then the result will be True, as for an empty row/column. If skipna is False, then NA are treated as True, because these are not equal to zero.

Returns
Series

Notes

Parameters currently not supported are axis, bool_only, level.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [3, 2, 3, 4], 'b': [7, 0, 10, 10]})
>>> df.all()
a     True
b    False
dtype: bool
any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs)

Return whether any elements is True in DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values. If the entire row/column is NA and skipna is True, then the result will be False, as for an empty row/column. If skipna is False, then NA are treated as True, because these are not equal to zero.

Returns
Series

Notes

Parameters currently not supported are axis, bool_only, level.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [3, 2, 3, 4], 'b': [7, 0, 10, 10]})
>>> df.any()
a    True
b    True
dtype: bool
apply_chunks(self, func, incols, outcols, kwargs={}, pessimistic_nulls=True, chunks=None, blkct=None, tpb=None)

Transform user-specified chunks using the user-provided function.

Parameters
dfDataFrame

The source dataframe.

funcfunction

The transformation function that will be executed on the CUDA GPU.

incols: list or dict

A list of names of input columns that match the function arguments. Or, a dictionary mapping input column names to their corresponding function arguments such as {‘col1’: ‘arg1’}.

outcols: dict

A dictionary of output column names and their dtype.

kwargs: dict

name-value of extra arguments. These values are passed directly into the function.

pessimistic_nullsbool

Whether or not apply_rows output should be null when any corresponding input is null. If False, all outputs will be non-null, but will be the result of applying func against the underlying column data, which may be garbage.

chunksint or Series-like

If it is an int, it is the chunksize. If it is an array, it contains integer offset for the start of each chunk. The span of a chunk for chunk i-th is data[chunks[i] : chunks[i + 1]] for any i + 1 < chunks.size; or, data[chunks[i]:] for the i == len(chunks) - 1.

tpbint; optional

The threads-per-block for the underlying kernel. If not specified (Default), uses Numba .forall(...) built-in to query the CUDA Driver API to determine optimal kernel launch configuration. Specify 1 to emulate serial execution for each chunk. It is a good starting point but inefficient. Its maximum possible value is limited by the available CUDA GPU resources.

blkctint; optional

The number of blocks for the underlying kernel. If not specified (Default) and tpb is not specified (Default), uses Numba .forall(...) built-in to query the CUDA Driver API to determine optimal kernel launch configuration. If not specified (Default) and tpb is specified, uses chunks as the number of blocks.

Examples

For tpb > 1, func is executed by tpb number of threads concurrently. To access the thread id and count, use numba.cuda.threadIdx.x and numba.cuda.blockDim.x, respectively (See numba CUDA kernel documentation).

In the example below, the kernel is invoked concurrently on each specified chunk. The kernel computes the corresponding output for the chunk.

By looping over the range range(cuda.threadIdx.x, in1.size, cuda.blockDim.x), the kernel function can be used with any tpb in an efficient manner.

>>> from numba import cuda
>>> @cuda.jit
... def kernel(in1, in2, in3, out1):
...      for i in range(cuda.threadIdx.x, in1.size, cuda.blockDim.x):
...          x = in1[i]
...          y = in2[i]
...          z = in3[i]
...          out1[i] = x * y + z
apply_rows(self, func, incols, outcols, kwargs, pessimistic_nulls=True, cache_key=None)

Apply a row-wise user defined function.

Parameters
dfDataFrame

The source dataframe.

funcfunction

The transformation function that will be executed on the CUDA GPU.

incols: list or dict

A list of names of input columns that match the function arguments. Or, a dictionary mapping input column names to their corresponding function arguments such as {‘col1’: ‘arg1’}.

outcols: dict

A dictionary of output column names and their dtype.

kwargs: dict

name-value of extra arguments. These values are passed directly into the function.

pessimistic_nullsbool

Whether or not apply_rows output should be null when any corresponding input is null. If False, all outputs will be non-null, but will be the result of applying func against the underlying column data, which may be garbage.

Examples

The user function should loop over the columns and set the output for each row. Loop execution order is arbitrary, so each iteration of the loop MUST be independent of each other.

When func is invoked, the array args corresponding to the input/output are strided so as to improve GPU parallelism. The loop in the function resembles serial code, but executes concurrently in multiple threads.

>>> import cudf
>>> import numpy as np
>>> df = cudf.DataFrame()
>>> nelem = 3
>>> df['in1'] = np.arange(nelem)
>>> df['in2'] = np.arange(nelem)
>>> df['in3'] = np.arange(nelem)

Define input columns for the kernel

>>> in1 = df['in1']
>>> in2 = df['in2']
>>> in3 = df['in3']
>>> def kernel(in1, in2, in3, out1, out2, kwarg1, kwarg2):
...     for i, (x, y, z) in enumerate(zip(in1, in2, in3)):
...         out1[i] = kwarg2 * x - kwarg1 * y
...         out2[i] = y - kwarg1 * z

Call .apply_rows with the name of the input columns, the name and dtype of the output columns, and, optionally, a dict of extra arguments.

>>> df.apply_rows(kernel,
...               incols=['in1', 'in2', 'in3'],
...               outcols=dict(out1=np.float64, out2=np.float64),
...               kwargs=dict(kwarg1=3, kwarg2=4))
   in1  in2  in3 out1 out2
0    0    0    0  0.0  0.0
1    1    1    1  1.0 -2.0
2    2    2    2  2.0 -4.0
argsort(self, ascending=True, na_position='last')

Sort by the values.

Parameters
ascendingbool or list of bool, default True

If True, sort values in ascending order, otherwise descending.

na_position{‘first’ or ‘last’}, default ‘last’

Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end.

Returns
out_column_indscuDF Column of indices sorted based on input

Notes

Difference from pandas:

  • Support axis=’index’ only.

  • Not supporting: inplace, kind

  • Ascending can be a list of bools to control per column

as_gpu_matrix(self, columns=None, order='F')

Convert to a matrix in device memory.

Parameters
columnssequence of str

List of a column names to be extracted. The order is preserved. If None is specified, all columns are used.

order‘F’ or ‘C’

Optional argument to determine whether to return a column major (Fortran) matrix or a row major (C) matrix.

Returns
A (nrow x ncol) numba device ndarray
as_matrix(self, columns=None)

Convert to a matrix in host memory.

Parameters
columnssequence of str

List of a column names to be extracted. The order is preserved. If None is specified, all columns are used.

Returns
A (nrow x ncol) numpy ndarray in “F” order.
assign(self, **kwargs)

Assign columns to DataFrame from keyword arguments.

Examples

>>> import cudf
>>> df = cudf.DataFrame()
>>> df = df.assign(a=[0, 1, 2], b=[3, 4, 5])
>>> print(df)
   a  b
0  0  3
1  1  4
2  2  5
astype(self, dtype, copy=False, errors='raise', **kwargs)

Cast the DataFrame to the given dtype

Parameters
dtypedata type, or dict of column name -> data type

Use a numpy.dtype or Python type to cast entire DataFrame object to the same type. Alternatively, use {col: dtype, ...}, where col is a column label and dtype is a numpy.dtype or Python type to cast one or more of the DataFrame’s columns to column-specific types.

copybool, default False

Return a deep-copy when copy=True. Note by default copy=False setting is used and hence changes to values then may propagate to other cudf objects.

errors{‘raise’, ‘ignore’, ‘warn’}, default ‘raise’

Control raising of exceptions on invalid data for provided dtype.

  • raise : allow exceptions to be raised

  • ignore : suppress exceptions. On error return original object.

  • warn : prints last exceptions as warnings and return original object.

**kwargsextra arguments to pass on to the constructor
Returns
castedDataFrame
property at

Alias for DataFrame.loc; provided for compatibility with Pandas.

property columns

Returns a tuple of columns

copy(self, deep=True)

Returns a copy of this dataframe

Parameters
deep: bool

Make a full copy of Series columns and Index at the GPU level, or create a new allocation with references.

corr(self)

Compute the correlation matrix of a DataFrame.

count(self, axis=0, level=None, numeric_only=False, **kwargs)

Count non-NA cells for each column or row.

The values None, NaN, NaT are considered NA.

Returns
Series

For each column/row the number of non-NA/null entries.

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> import numpy as np
>>> df = cudf.DataFrame({"Person":
           ["John", "Myla", "Lewis", "John", "Myla"],
           "Age": [24., np.nan, 21., 33, 26],
           "Single": [False, True, True, True, False]})
>>> df.count()
Person    5
Age       4
Single    5
dtype: int64
cov(self, **kwargs)

Compute the covariance matrix of a DataFrame.

Parameters
**kwargs

Keyword arguments to be passed to cupy.cov

Returns
covDataFrame
cummax(self, axis=None, skipna=True, *args, **kwargs)

Return cumulative maximum of the DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

Returns
DataFrame

Notes

Parameters currently not supported is axis

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.cummax()
   a   b
0  1   7
1  2   8
2  3   9
3  4  10
cummin(self, axis=None, skipna=True, *args, **kwargs)

Return cumulative minimum of the DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

Returns
DataFrame

Notes

Parameters currently not supported is axis

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.cummin()
   a  b
0  1  7
1  1  7
2  1  7
3  1  7
cumprod(self, axis=None, skipna=True, *args, **kwargs)

Return cumulative product of the DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

Returns
DataFrame

Notes

Parameters currently not supported is axis

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> s.cumprod()
    a     b
0   1     7
1   2    56
2   6   504
3  24  5040
cumsum(self, axis=None, skipna=True, *args, **kwargs)

Return cumulative sum of the DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

Returns
DataFrame

Notes

Parameters currently not supported is axis

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> s.cumsum()
    a   b
0   1   7
1   3  15
2   6  24
3  10  34
describe(self, percentiles=None, include=None, exclude=None)

Compute summary statistics of a DataFrame’s columns. For numeric data, the output includes the minimum, maximum, mean, median, standard deviation, and various quantiles. For object data, the output includes the count, number of unique values, the most common value, and the number of occurrences of the most common value.

Parameters
percentileslist-like, optional

The percentiles used to generate the output summary statistics. If None, the default percentiles used are the 25th, 50th and 75th. Values should be within the interval [0, 1].

include: str, list-like, optional

The dtypes to be included in the output summary statistics. Columns of dtypes not included in this list will not be part of the output. If include=’all’, all dtypes are included. Default of None includes all numeric columns.

exclude: str, list-like, optional

The dtypes to be excluded from the output summary statistics. Columns of dtypes included in this list will not be part of the output. Default of None excludes no columns.

Returns
output_frameDataFrame

Summary statistics of relevant columns in the original dataframe.

Examples

Describing a Series containing numeric values.

>>> import cudf
>>> s = cudf.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> print(s.describe())
   stats   values
0  count     10.0
1   mean      5.5
2    std  3.02765
3    min      1.0
4    25%      2.5
5    50%      5.5
6    75%      7.5
7    max     10.0

Describing a DataFrame. By default all numeric fields are returned.

>>> gdf = cudf.DataFrame()
>>> gdf['a'] = [1,2,3]
>>> gdf['b'] = [1.0, 2.0, 3.0]
>>> gdf['c'] = ['x', 'y', 'z']
>>> gdf['d'] = [1.0, 2.0, 3.0]
>>> gdf['d'] = gdf['d'].astype('float32')
>>> print(gdf.describe())
   stats    a    b    d
0  count  3.0  3.0  3.0
1   mean  2.0  2.0  2.0
2    std  1.0  1.0  1.0
3    min  1.0  1.0  1.0
4    25%  1.5  1.5  1.5
5    50%  1.5  1.5  1.5
6    75%  2.5  2.5  2.5
7    max  3.0  3.0  3.0

Using the include keyword to describe only specific dtypes.

>>> gdf = cudf.DataFrame()
>>> gdf['a'] = [1,2,3]
>>> gdf['b'] = [1.0, 2.0, 3.0]
>>> gdf['c'] = ['x', 'y', 'z']
>>> print(gdf.describe(include='int'))
   stats    a
0  count  3.0
1   mean  2.0
2    std  1.0
3    min  1.0
4    25%  1.5
5    50%  1.5
6    75%  2.5
7    max  3.0
div(self, other, axis='columns', level=None, fill_value=None)

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: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df.truediv(10)
            angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0
>>> df.div(10)
            angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0
>>> df / 10
            angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0
drop(self, labels=None, axis=None, columns=None, errors='raise', inplace=False)

Drop column(s)

Parameters
labelsstr or sequence of strings

Name of column(s) to be dropped.

axis{0 or ‘index’, 1 or ‘columns’}, default 0

Only axis=1 is currently supported.

columns

array of column names, the same as using labels and axis=1

errors{‘ignore’, ‘raise’}, default ‘raise’

This parameter is currently ignored.

inplacebool, default False

If True, do operation inplace and return self.

Returns
A dataframe without dropped column(s)

Examples

>>> import cudf
>>> df = cudf.DataFrame()
>>> df['key'] = [0, 1, 2, 3, 4]
>>> df['val'] = [float(i + 10) for i in range(5)]
>>> df_new = df.drop('val')
>>> print(df)
   key   val
0    0  10.0
1    1  11.0
2    2  12.0
3    3  13.0
4    4  14.0
>>> print(df_new)
   key
0    0
1    1
2    2
3    3
4    4
drop_column(self, name)

Drop a column by name

drop_duplicates(self, subset=None, keep='first', inplace=False, ignore_index=False)

Return DataFrame with duplicate rows removed, optionally only considering certain subset of columns.

property dtypes

Return the dtypes in this object.

property empty

Indicator whether DataFrame is empty.

True if DataFrame is entirely empty (no items), meaning any of the axes are of length 0.

Returns
outbool

If DataFrame is empty, return True, if not return False.

equals(self, other)

Test whether two objects contain the same elements. This function allows two Series or DataFrames to be compared against each other to see if they have the same shape and elements. NaNs in the same location are considered equal. The column headers do not need to have the same type.

Parameters
otherSeries or DataFrame

The other Series or DataFrame to be compared with the first.

Returns
bool

True if all elements are the same in both objects, False otherwise.

Examples

>>> import cudf
>>> df = cudf.DataFrame({1: [10], 2: [20]})
>>> df
    1   2
0  10  20
>>> exactly_equal = cudf.DataFrame({1: [10], 2: [20]})
>>> exactly_equal
    1   2
0  10  20
>>> df.equals(exactly_equal)
True
>>> different_column_type = cudf.DataFrame({1.0: [10], 2.0: [20]})
>>> different_column_type
   1.0  2.0
0   10   20
>>> df.equals(different_column_type)
True
fillna(self, value, method=None, axis=None, inplace=False, limit=None)

Fill null values with value.

Parameters
valuescalar, Series-like or dict

Value to use to fill nulls. If Series-like, null values are filled with values in corresponding indices. A dict can be used to provide different values to fill nulls in different columns.

Returns
resultDataFrame

Copy with nulls filled.

Examples

>>> import cudf
>>> gdf = cudf.DataFrame({'a': [1, 2, None], 'b': [3, None, 5]})
>>> gdf.fillna(4).to_pandas()
a  b
0  1  3
1  2  4
2  4  5
>>> gdf.fillna({'a': 3, 'b': 4}).to_pandas()
a  b
0  1  3
1  2  4
2  3  5
floordiv(self, other, axis='columns', level=None, fill_value=None)

Get Integer division of dataframe and other, element-wise (binary operator floordiv).

Equivalent to dataframe // other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rfloordiv.

Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [1, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df.floordiv(2)
        angles  degrees
circle          0      180
triangle        1       90
rectangle       2      180
>>> df // 2
        angles  degrees
circle          0      180
triangle        1       90
rectangle       2      180
classmethod from_arrow(table)

Convert from a PyArrow Table.

Parameters
tablePyArrow Table Object

PyArrow Table Object which has to be converted to cudf DataFrame.

Raises
TypeError for invalid input type.

Notes

  • Does not support automatically setting index column(s) similar to how to_pandas works for PyArrow Tables.

Examples

>>> import pyarrow as pa
>>> import cudf
>>> data = [pa.array([1, 2, 3]), pa.array([4, 5, 6])]
>>> batch = pa.RecordBatch.from_arrays(data, ['f0', 'f1'])
>>> table = pa.Table.from_batches([batch])
>>> cudf.DataFrame.from_arrow(table)
    f0  f1
0   1   4
1   2   5
2   3   6
classmethod from_gpu_matrix(data, index=None, columns=None, nan_as_null=False)

Convert from a numba gpu ndarray.

Parameters
datanumba gpu ndarray
indexstr, Index

The name of the index column in data or an Index itself. If None, the default index is used.

columnslist of str

List of column names to include.

Returns
DataFrame
classmethod from_pandas(dataframe, nan_as_null=None)

Convert from a Pandas DataFrame.

Parameters
dataframePandas DataFrame object

A Pandads DataFrame object which has to be converted to cuDF DataFrame.

nan_as_nullbool, Default True

If True, converts np.nan values to null values. If False, leaves np.nan values as is.

Raises
TypeError for invalid input type.

Examples

>>> import cudf
>>> import pandas as pd
>>> data = [[0,1], [1,2], [3,4]]
>>> pdf = pd.DataFrame(data, columns=['a', 'b'], dtype=int)
>>> cudf.from_pandas(pdf)
   a  b
0  0  1
1  1  2
2  3  4
classmethod from_records(data, index=None, columns=None, nan_as_null=False)

Convert structured or record ndarray to DataFrame.

Parameters
datanumpy structured dtype or recarray of ndim=2
indexstr, array-like

The name of the index column in data. If None, the default index is used.

columnslist of str

List of column names to include.

Returns
DataFrame
groupby(self, by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=False, observed=False, dropna=True, method=None)

Group DataFrame using a mapper or by a Series of columns.

A groupby operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group large amounts of data and compute operations on these groups.

Parameters
bymapping, function, label, or list of labels

Used to determine the groups for the groupby. If by is a function, it’s called on each value of the object’s index. If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups (the Series’ values are first aligned; see .align() method). If a cupy array is passed, the values are used as-is determine the groups. A label or list of labels may be passed to group by the columns in self. Notice that a tuple is interpreted as a (single) key.

levelint, level name, or sequence of such, default None

If the axis is a MultiIndex (hierarchical), group by a particular level or levels.

as_indexbool, default True

For aggregated output, return object with group labels as the index. Only relevant for DataFrame input. as_index=False is effectively “SQL-style” grouped output.

sortbool, default True

Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each group. Groupby preserves the order of rows within each group.

dropnabool, optional

If True (default), do not include the “null” group.

Returns
DataFrameGroupBy

Returns a groupby object that contains information about the groups.

Examples

>>> import cudf
>>> import pandas as pd
>>> df = cudf.DataFrame({'Animal': ['Falcon', 'Falcon',
...                               'Parrot', 'Parrot'],
...                    'Max Speed': [380., 370., 24., 26.]})
>>> df
Animal  Max Speed
0  Falcon      380.0
1  Falcon      370.0
2  Parrot       24.0
3  Parrot       26.0
>>> df.groupby(['Animal']).mean()
        Max Speed
Animal
Falcon      375.0
Parrot       25.0
>>> arrays = [['Falcon', 'Falcon', 'Parrot', 'Parrot'],
['Captive', 'Wild', 'Captive', 'Wild']]
>>> index = pd.MultiIndex.from_arrays(arrays, names=('Animal', 'Type'))
>>> df = cudf.DataFrame({'Max Speed': [390., 350., 30., 20.]},
        index=index)
>>> df
                Max Speed
Animal Type
Falcon Captive      390.0
    Wild         350.0
Parrot Captive       30.0
    Wild          20.0
>>> df.groupby(level=0).mean()
        Max Speed
Animal
Falcon      370.0
Parrot       25.0
>>> df.groupby(level="Type").mean()
        Max Speed
Type
Captive      210.0
Wild         185.0
hash_columns(self, columns=None)

Hash the given columns and return a new device array

Parameters
columnssequence of str; optional

Sequence of column names. If columns is None (unspecified), all columns in the frame are used.

head(self, n=5)

Returns the first n rows as a new DataFrame

Examples

>>> import cudf
>>> df = cudf.DataFrame()
>>> df['key'] = [0, 1, 2, 3, 4]
>>> df['val'] = [float(i + 10) for i in range(5)]  # insert column
>>> print(df.head(2))
   key   val
0    0  10.0
1    1  11.0
property iat

Alias for DataFrame.iloc; provided for compatibility with Pandas.

property iloc

Selecting rows and column by position.

See also

DataFrame.loc

Notes

One notable difference from Pandas is when DataFrame is of mixed types and result is expected to be a Series in case of Pandas. cuDF will return a DataFrame as it doesn’t support mixed types under Series yet.

Mixed dtype single row output as a dataframe (pandas results in Series)

>>> import cudf
>>> df = cudf.DataFrame({"a":[1, 2, 3], "b":["a", "b", "c"]})
>>> df.iloc[0]
   a  b
0  1  a

Examples

>>> df = cudf.DataFrame({'a': range(20),
...                      'b': range(20),
...                      'c': range(20)})

Select a single row using an integer index.

>>> print(df.iloc[1])
a    1
b    1
c    1

Select multiple rows using a list of integers.

>>> print(df.iloc[[0, 2, 9, 18]])
      a    b    c
 0    0    0    0
 2    2    2    2
 9    9    9    9
18   18   18   18

Select rows using a slice.

>>> print(df.iloc[3:10:2])
     a    b    c
3    3    3    3
5    5    5    5
7    7    7    7
9    9    9    9

Select both rows and columns.

>>> print(df.iloc[[1, 3, 5, 7], 2])
1    1
3    3
5    5
7    7
Name: c, dtype: int64

Setting values in a column using iloc.

>>> df.iloc[:4] = 0
>>> print(df)
   a  b  c
0  0  0  0
1  0  0  0
2  0  0  0
3  0  0  0
4  4  4  4
5  5  5  5
6  6  6  6
7  7  7  7
8  8  8  8
9  9  9  9
[10 more rows]
property index

Returns the index of the DataFrame

info(self, verbose=None, buf=None, max_cols=None, memory_usage=None, null_counts=None)

Print a concise summary of a DataFrame.

This method prints information about a DataFrame including the index dtype and column dtypes, non-null values and memory usage.

Parameters
verbosebool, optional

Whether to print the full summary. By default, the setting in pandas.options.display.max_info_columns is followed.

bufwritable buffer, defaults to sys.stdout

Where to send the output. By default, the output is printed to sys.stdout. Pass a writable buffer if you need to further process the output.

max_colsint, optional

When to switch from the verbose to the truncated output. If the DataFrame has more than max_cols columns, the truncated output is used. By default, the setting in pandas.options.display.max_info_columns is used.

memory_usagebool, str, optional

Specifies whether total memory usage of the DataFrame elements (including the index) should be displayed. By default, this follows the pandas.options.display.memory_usage setting. True always show memory usage. False never shows memory usage. A value of ‘deep’ is equivalent to “True with deep introspection”. Memory usage is shown in human-readable units (base-2 representation). Without deep introspection a memory estimation is made based in column dtype and number of rows assuming values consume the same memory amount for corresponding dtypes. With deep memory introspection, a real memory usage calculation is performed at the cost of computational resources.

null_countsbool, optional

Whether to show the non-null counts. By default, this is shown only if the frame is smaller than pandas.options.display.max_info_rows and pandas.options.display.max_info_columns. A value of True always shows the counts, and False never shows the counts.

Returns
None

This method prints a summary of a DataFrame and returns None.

See also

DataFrame.describe

Generate descriptive statistics of DataFrame columns.

DataFrame.memory_usage

Memory usage of DataFrame columns.

Examples

>>> import cudf
>>> int_values = [1, 2, 3, 4, 5]
>>> text_values = ['alpha', 'beta', 'gamma', 'delta', 'epsilon']
>>> float_values = [0.0, 0.25, 0.5, 0.75, 1.0]
>>> df = cudf.DataFrame({"int_col": int_values,
...                     "text_col": text_values,
...                     "float_col": float_values})
>>> df
   int_col text_col  float_col
0        1    alpha       0.00
1        2     beta       0.25
2        3    gamma       0.50
3        4    delta       0.75
4        5  epsilon       1.00

Prints information of all columns:

>>> df.info(verbose=True)
<class 'cudf.core.dataframe.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Data columns (total 3 columns):
 #   Column     Non-Null Count  Dtype
---  ------     --------------  -----
 0   int_col    5 non-null      int64
 1   text_col   5 non-null      object
 2   float_col  5 non-null      float64
dtypes: float64(1), int64(1), object(1)
memory usage: 130.0+ bytes

Prints a summary of columns count and its dtypes but not per column information:

>>> df.info(verbose=False)
<class 'cudf.core.dataframe.DataFrame'>
RangeIndex: 5 entries, 0 to 4
Columns: 3 entries, int_col to float_col
dtypes: float64(1), int64(1), object(1)
memory usage: 130.0+ bytes

Pipe output of DataFrame.info to buffer instead of sys.stdout, get buffer content and writes to a text file:

>>> import io
>>> buffer = io.StringIO()
>>> df.info(buf=buffer)
>>> s = buffer.getvalue()
>>> with open("df_info.txt", "w",
...           encoding="utf-8") as f:
...     f.write(s)
...
369

The memory_usage parameter allows deep introspection mode, specially useful for big DataFrames and fine-tune memory optimization:

>>> import numpy as np
>>> random_strings_array = np.random.choice(['a', 'b', 'c'], 10 ** 6)
>>> df = cudf.DataFrame({
...     'column_1': np.random.choice(['a', 'b', 'c'], 10 ** 6),
...     'column_2': np.random.choice(['a', 'b', 'c'], 10 ** 6),
...     'column_3': np.random.choice(['a', 'b', 'c'], 10 ** 6)
... })
>>> df.info(memory_usage='deep')
<class 'cudf.core.dataframe.DataFrame'>
RangeIndex: 1000000 entries, 0 to 999999
Data columns (total 3 columns):
 #   Column    Non-Null Count    Dtype
---  ------    --------------    -----
 0   column_1  1000000 non-null  object
 1   column_2  1000000 non-null  object
 2   column_3  1000000 non-null  object
dtypes: object(3)
memory usage: 14.3 MB
insert(self, loc, name, value)

Add a column to DataFrame at the index specified by loc.

Parameters
locint

location to insert by index, cannot be greater then num columns + 1

namenumber or string

name or label of column to be inserted

valueSeries or array-like
isin(self, values)

Whether each element in the DataFrame is contained in values.

Parameters
valuesiterable, Series, DataFrame or dict

The result will only be true at a location if all the labels match. If values is a Series, that’s the index. If values is a dict, the keys must be the column names, which must match. If values is a DataFrame, then both the index and column labels must match.

Returns
DataFrame:

DataFrame of booleans showing whether each element in the DataFrame is contained in values.

iteritems(self)

Iterate over column names and series pairs

join(self, other, on=None, how='left', lsuffix='', rsuffix='', sort=False, type='', method='hash')

Join columns with other DataFrame on index or on a key column.

Parameters
otherDataFrame
howstr

Only accepts “left”, “right”, “inner”, “outer”

lsuffix, rsuffixstr

The suffices to add to the left (lsuffix) and right (rsuffix) column names when avoiding conflicts.

sortbool

Set to True to ensure sorted ordering.

Returns
joinedDataFrame

Notes

Difference from pandas:

  • other must be a single DataFrame for now.

  • on is not supported yet due to lack of multi-index support.

kurt(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Return Fisher’s unbiased kurtosis of a sample.

Kurtosis obtained using Fisher’s definition of kurtosis (kurtosis of normal == 0.0). Normalized by N-1.

Parameters
skipna: bool, default True

Exclude NA/null values when computing the result.

Returns
Series

Notes

Parameters currently not supported are axis, level and numeric_only

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.kurt()
a   -1.2
b   -1.2
dtype: float64
kurtosis(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Return Fisher’s unbiased kurtosis of a sample.

Kurtosis obtained using Fisher’s definition of kurtosis (kurtosis of normal == 0.0). Normalized by N-1.

Parameters
skipna: bool, default True

Exclude NA/null values when computing the result.

Returns
Series

Notes

Parameters currently not supported are axis, level and numeric_only

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.kurt()
a   -1.2
b   -1.2
dtype: float64
label_encoding(self, column, prefix, cats, prefix_sep='_', dtype=None, na_sentinel=- 1)

Encode labels in a column with label encoding.

Parameters
columnstr

the source column with binary encoding for the data.

prefixstr

the new column name prefix.

catssequence of ints

the sequence of categories as integers.

prefix_sepstr

the separator between the prefix and the category.

dtype :

the dtype for the outputs; see Series.label_encoding

na_sentinelnumber

Value to indicate missing category.

Returns
a new dataframe with a new column append for the coded values.
property loc

Selecting rows and columns by label or boolean mask.

See also

DataFrame.iloc

Notes

One notable difference from Pandas is when DataFrame is of mixed types and result is expected to be a Series in case of Pandas. cuDF will return a DataFrame as it doesn’t support mixed types under Series yet.

Mixed dtype single row output as a dataframe (pandas results in Series)

>>> import cudf
>>> df = cudf.DataFrame({"a":[1, 2, 3], "b":["a", "b", "c"]})
>>> df.loc[0]
   a  b
0  1  a

Examples

DataFrame with string index.

>>> print(df)
   a  b
a  0  5
b  1  6
c  2  7
d  3  8
e  4  9

Select a single row by label.

>>> print(df.loc['a'])
a    0
b    5
Name: a, dtype: int64

Select multiple rows and a single column.

>>> print(df.loc[['a', 'c', 'e'], 'b'])
a    5
c    7
e    9
Name: b, dtype: int64

Selection by boolean mask.

>>> print(df.loc[df.a > 2])
   a  b
d  3  8
e  4  9

Setting values using loc.

>>> df.loc[['a', 'c', 'e'], 'a'] = 0
>>> print(df)
   a  b
a  0  5
b  1  6
c  0  7
d  3  8
e  0  9
max(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, **kwargs)

Return the maximum of the values in the DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values when computing the result.

dtype: data type

Data type to cast the result to.

Returns
Series

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.max()
a     4
b    10
dtype: int64
mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Return the mean of the values for the requested axis.

Parameters
axis{0 or ‘index’, 1 or ‘columns’}

Axis for the function to be applied on.

skipnabool, default True

Exclude NA/null values when computing the result.

levelint or level name, default None

If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a Series.

numeric_onlybool, default None

Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.

**kwargs

Additional keyword arguments to be passed to the function.

Returns
meanSeries or DataFrame (if level specified)

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.mean()
a    2.5
b    8.5
dtype: float64
melt(self, **kwargs)

Unpivots a DataFrame from wide format to long format, optionally leaving identifier variables set.

Parameters
frameDataFrame
id_varstuple, list, or ndarray, optional

Column(s) to use as identifier variables. default: None

value_varstuple, list, or ndarray, optional

Column(s) to unpivot. default: all columns that are not set as id_vars.

var_namescalar

Name to use for the variable column. default: frame.columns.name or ‘variable’

value_namestr

Name to use for the value column. default: ‘value’

Returns
outDataFrame

Melted result

memory_usage(self, index=True, deep=False)

Return the memory usage of each column in bytes. The memory usage can optionally include the contribution of the index and elements of object dtype.

Parameters
indexbool, default True

Specifies whether to include the memory usage of the DataFrame’s index in returned Series. If index=True, the memory usage of the index is the first item in the output.

deepbool, default False

If True, introspect the data deeply by interrogating object dtypes for system-level memory consumption, and include it in the returned values.

Returns
Series

A Series whose index is the original column names and whose values is the memory usage of each column in bytes.

Examples

>>> dtypes = ['int64', 'float64', 'object', 'bool']
>>> data = dict([(t, np.ones(shape=5000).astype(t))
...              for t in dtypes])
>>> df = cudf.DataFrame(data)
>>> df.head()
    int64  float64  object  bool
0      1      1.0     1.0  True
1      1      1.0     1.0  True
2      1      1.0     1.0  True
3      1      1.0     1.0  True
4      1      1.0     1.0  True
>>> df.memory_usage(index=False)
int64      40000
float64    40000
object     40000
bool        5000
dtype: int64
Use a Categorical for efficient storage of an object-dtype column with
many repeated values.
>>> df['object'].astype('category').memory_usage(deep=True)
5048
merge(self, right, on=None, left_on=None, right_on=None, left_index=False, right_index=False, how='inner', sort=False, lsuffix=None, rsuffix=None, type='', method='hash', indicator=False, suffixes='_x', '_y')

Merge GPU DataFrame objects by performing a database-style join operation by columns or indexes.

Parameters
rightDataFrame
onlabel or list; defaults to None

Column or index level names to join on. These must be found in both DataFrames.

If on is None and not merging on indexes then this defaults to the intersection of the columns in both DataFrames.

how{‘left’, ‘outer’, ‘inner’}, default ‘inner’

Type of merge to be performed.

  • left : use only keys from left frame, similar to a SQL left outer join.

  • right : not supported.

  • outer : use union of keys from both frames, similar to a SQL full outer join.

  • inner: use intersection of keys from both frames, similar to a SQL inner join.

left_onlabel or list, or array-like

Column or index level names to join on in the left DataFrame. Can also be an array or list of arrays of the length of the left DataFrame. These arrays are treated as if they are columns.

right_onlabel or list, or array-like

Column or index level names to join on in the right DataFrame. Can also be an array or list of arrays of the length of the right DataFrame. These arrays are treated as if they are columns.

left_indexbool, default False

Use the index from the left DataFrame as the join key(s).

right_indexbool, default False

Use the index from the right DataFrame as the join key.

sortbool, default False

Sort the resulting dataframe by the columns that were merged on, starting from the left.

suffixes: Tuple[str, str], defaults to (‘_x’, ‘_y’)

Suffixes applied to overlapping column names on the left and right sides

method{‘hash’, ‘sort’}, default ‘hash’

The implementation method to be used for the operation.

Returns
mergedDataFrame

Notes

DataFrames merges in cuDF result in non-deterministic row ordering.

Examples

>>> import cudf
>>> df_a = cudf.DataFrame()
>>> df_a['key'] = [0, 1, 2, 3, 4]
>>> df_a['vals_a'] = [float(i + 10) for i in range(5)]
>>> df_b = cudf.DataFrame()
>>> df_b['key'] = [1, 2, 4]
>>> df_b['vals_b'] = [float(i+10) for i in range(3)]
>>> df_merged = df_a.merge(df_b, on=['key'], how='left')
>>> df_merged.sort_values('key')  
   key  vals_a  vals_b
3    0    10.0
0    1    11.0    10.0
1    2    12.0    11.0
4    3    13.0
2    4    14.0    12.0
min(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, **kwargs)

Return the minimum of the values in the DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values when computing the result.

dtype: data type

Data type to cast the result to.

Returns
Series

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.min()
a    1
b    7
dtype: int64
mod(self, other, axis='columns', level=None, fill_value=None)

Get Modulo division of dataframe and other, element-wise (binary operator mod).

Equivalent to dataframe % other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rmod.

Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df % 100
        angles  degrees
circle          0       60
triangle        3       80
rectangle       4       60
>>> df.mod(100)
        angles  degrees
circle          0       60
triangle        3       80
rectangle       4       60
mul(self, other, axis='columns', level=None, fill_value=None)

Get Multiplication of dataframe and other, element-wise (binary operator mul).

Equivalent to dataframe * other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rmul.

Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> other = pd.DataFrame({'angles': [0, 3, 4]},
...                      index=['circle', 'triangle', 'rectangle'])
>>> df * other
        angles degrees
circle          0    null
triangle        9    null
rectangle      16    null
>>> df.mul(other, fill_value=0)
        angles  degrees
circle          0        0
triangle        9        0
rectangle      16        0
nans_to_nulls(self)

Convert nans (if any) to nulls.

property ndim

Dimension of the data. DataFrame ndim is always 2.

nlargest(self, n, columns, keep='first')

Get the rows of the DataFrame sorted by the n largest value of columns

Notes

Difference from pandas:
  • Only a single column is supported in columns

nsmallest(self, n, columns, keep='first')

Get the rows of the DataFrame sorted by the n smallest value of columns

Notes

Difference from pandas:
  • Only a single column is supported in columns

one_hot_encoding(self, column, prefix, cats, prefix_sep='_', dtype='float64')

Expand a column with one-hot-encoding.

Parameters
columnstr

the source column with binary encoding for the data.

prefixstr

the new column name prefix.

catssequence of ints

the sequence of categories as integers.

prefix_sepstr

the separator between the prefix and the category.

dtype :

the dtype for the outputs; defaults to float64.

Returns
a new dataframe with new columns append for each category.

Examples

>>> import pandas as pd
>>> import cudf
>>> pet_owner = [1, 2, 3, 4, 5]
>>> pet_type = ['fish', 'dog', 'fish', 'bird', 'fish']
>>> df = pd.DataFrame({'pet_owner': pet_owner, 'pet_type': pet_type})
>>> df.pet_type = df.pet_type.astype('category')

Create a column with numerically encoded category values

>>> df['pet_codes'] = df.pet_type.cat.codes
>>> gdf = cudf.from_pandas(df)

Create the list of category codes to use in the encoding

>>> codes = gdf.pet_codes.unique()
>>> gdf.one_hot_encoding('pet_codes', 'pet_dummy', codes).head()
  pet_owner  pet_type  pet_codes  pet_dummy_0  pet_dummy_1  pet_dummy_2
0         1      fish          2          0.0          0.0          1.0
1         2       dog          1          0.0          1.0          0.0
2         3      fish          2          0.0          0.0          1.0
3         4      bird          0          1.0          0.0          0.0
4         5      fish          2          0.0          0.0          1.0
partition_by_hash(self, columns, nparts, keep_index=True)

Partition the dataframe by the hashed value of data in columns.

Parameters
columnssequence of str

The names of the columns to be hashed. Must have at least one name.

npartsint

Number of output partitions

keep_indexboolean

Whether to keep the index or drop it

Returns
partitioned: list of DataFrame
pop(self, item)

Return a column and drop it from the DataFrame.

pow(self, other, axis='columns', level=None, fill_value=None)

Get Exponential power of dataframe and other, element-wise (binary operator pow).

Equivalent to dataframe ** other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, rpow.

Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [1, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df ** 2
        angles  degrees
circle          0   129600
triangle        9    32400
rectangle      16   129600
>>> df.pow(2)
        angles  degrees
circle          0   129600
triangle        9    32400
rectangle      16   129600
prod(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, min_count=0, **kwargs)

Return product of the values in the DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values when computing the result.

dtype: data type

Data type to cast the result to.

min_count: int, default 0

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.

The default being 0. This means the sum of an all-NA or empty Series is 0, and the product of an all-NA or empty Series is 1.

Returns
scalar

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.prod()
a      24
b    5040
dtype: int64
product(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, min_count=0, **kwargs)

Return product of the values in the DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values when computing the result.

dtype: data type

Data type to cast the result to.

min_count: int, default 0

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.

The default being 0. This means the sum of an all-NA or empty Series is 0, and the product of an all-NA or empty Series is 1.

Returns
Series

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.product()
a      24
b    5040
dtype: int64
quantile(self, q=0.5, axis=0, numeric_only=True, interpolation='linear', columns=None, exact=True)

Return values at the given quantile.

Parameters
qfloat or array-like

0 <= q <= 1, the quantile(s) to compute

axisint

axis is a NON-FUNCTIONAL parameter

numeric_onlyboolean

numeric_only is a NON-FUNCTIONAL parameter

interpolation{linear, lower, higher, midpoint, nearest}

This parameter specifies the interpolation method to use, when the desired quantile lies between two data points i and j. Default linear.

columnslist of str

List of column names to include.

exactboolean

Whether to use approximate or exact quantile algorithm.

Returns
DataFrame
quantiles(self, q=0.5, interpolation='nearest')

Return values at the given quantile.

Parameters
qfloat or array-like

0 <= q <= 1, the quantile(s) to compute

interpolation{lower, higher, nearest}

This parameter specifies the interpolation method to use, when the desired quantile lies between two data points i and j. Default ‘nearest’.

Returns
DataFrame
query(self, expr, local_dict={})

Query with a boolean expression using Numba to compile a GPU kernel.

See pandas.DataFrame.query.

Parameters
exprstr

A boolean expression. Names in expression refer to columns. index can be used instead of index name, but this is not supported for MultiIndex.

Names starting with @ refer to Python variables.

An output value will be null if any of the input values are null regardless of expression.

local_dictdict

Containing the local variable to be used in query.

Returns
filteredDataFrame

Examples

>>> import cudf
>>> a = ('a', [1, 2, 2])
>>> b = ('b', [3, 4, 5])
>>> df = cudf.DataFrame([a, b])
>>> expr = "(a == 2 and b == 4) or (b == 3)"
>>> print(df.query(expr))
   a  b
0  1  3
1  2  4

DateTime conditionals:

>>> import numpy as np
>>> import datetime
>>> df = cudf.DataFrame()
>>> data = np.array(['2018-10-07', '2018-10-08'], dtype='datetime64')
>>> df['datetimes'] = data
>>> search_date = datetime.datetime.strptime('2018-10-08', '%Y-%m-%d')
>>> print(df.query('datetimes==@search_date'))
                datetimes
1 2018-10-08T00:00:00.000

Using local_dict:

>>> import numpy as np
>>> import datetime
>>> df = cudf.DataFrame()
>>> data = np.array(['2018-10-07', '2018-10-08'], dtype='datetime64')
>>> df['datetimes'] = data
>>> search_date2 = datetime.datetime.strptime('2018-10-08', '%Y-%m-%d')
>>> print(df.query('datetimes==@search_date',
>>>         local_dict={'search_date':search_date2}))
                datetimes
1 2018-10-08T00:00:00.000
radd(self, other, axis=1, level=None, fill_value=None)

Get Addition of dataframe and other, element-wise (binary operator radd).

Equivalent to other + dataframe, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, add.

Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df + 1
        angles  degrees
circle          1      361
triangle        4      181
rectangle       5      361
>>> df.radd(1)
        angles  degrees
circle          1      361
triangle        4      181
rectangle       5      361
rdiv(self, other, axis='columns', level=None, fill_value=None)

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: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df.rtruediv(10)
            angles   degrees
circle          inf  0.027778
triangle   3.333333  0.055556
rectangle  2.500000  0.027778
>>> df.rdiv(10)
            angles   degrees
circle          inf  0.027778
triangle   3.333333  0.055556
rectangle  2.500000  0.027778
>>> 10 / df
            angles   degrees
circle          inf  0.027778
triangle   3.333333  0.055556
rectangle  2.500000  0.027778
reindex(self, labels=None, axis=0, index=None, columns=None, copy=True)

Return a new DataFrame whose axes conform to a new index

DataFrame.reindex supports two calling conventions:
  • (index=index_labels, columns=column_names)

  • (labels, axis={0 or 'index', 1 or 'columns'})

Parameters
labelsIndex, Series-convertible, optional, default None
axis{0 or ‘index’, 1 or ‘columns’}, optional, default 0
indexIndex, Series-convertible, optional, default None

Shorthand for df.reindex(labels=index_labels, axis=0)

columnsarray-like, optional, default None

Shorthand for df.reindex(labels=column_names, axis=1)

copyboolean, optional, default True
Returns
A DataFrame whose axes conform to the new index(es)

Examples

>>> import cudf
>>> df = cudf.DataFrame()
>>> df['key'] = [0, 1, 2, 3, 4]
>>> df['val'] = [float(i + 10) for i in range(5)]
>>> df_new = df.reindex(index=[0, 3, 4, 5],
                        columns=['key', 'val', 'sum'])
>>> print(df)
   key   val
0    0  10.0
1    1  11.0
2    2  12.0
3    3  13.0
4    4  14.0
>>> print(df_new)
   key   val  sum
0    0  10.0  NaN
3    3  13.0  NaN
4    4  14.0  NaN
5   -1   NaN  NaN
rename(self, mapper=None, index=None, columns=None, axis=0, copy=True, inplace=False, level=None, errors='ignore')

Alter column and index labels.

Function / dict values must be unique (1-to-1). Labels not contained in a dict / Series will be left as-is. Extra labels listed don’t throw an error.

DataFrame.rename supports two calling conventions

(index=index_mapper, columns=columns_mapper, ...) (mapper, axis={0/'index' or 1/'column'}, ...)

We highly recommend using keyword arguments to clarify your intent.

Parameters
mapperdict-like or function, default None

optional dict-like or functions transformations to apply to the index/column values depending on selected axis.

indexdict-like, default None

Optional dict-like transformations to apply to the index axis’ values. Does not support functions for axis 0 yet.

columnsdict-like or function, default None

optional dict-like or functions transformations to apply to the columns axis’ values.

axisint, default 0

Axis to rename with mapper. 0 or ‘index’ for index 1 or ‘columns’ for columns

copyboolean, default True

Also copy underlying data

inplaceboolean, default False

Return new DataFrame. If True, assign columns without copy

levelint or level name, default None

In case of a MultiIndex, only rename labels in the specified level.

errors{‘raise’, ‘ignore’, ‘warn’}, default ‘ignore’

Only ‘ignore’ supported Control raising of exceptions on invalid data for provided dtype.

  • raise : allow exceptions to be raised

  • ignore : suppress exceptions. On error return original object.

  • warn : prints last exceptions as warnings and return original object.

Returns
DataFrame

Notes

Difference from pandas:
  • Not supporting: level

Rename will not overwite column names. If a list with duplicates is passed, column names will be postfixed with a number.

replace(self, to_replace=None, value=None, inplace=False, limit=None, regex=False, method=None)

Replace values given in to_replace with replacement.

Parameters
to_replacenumeric, str, list-like or dict

Value(s) to replace.

  • numeric or str:

    • values equal to to_replace will be replaced with replacement

  • list of numeric or str:

    • If replacement is also list-like, to_replace and replacement must be of same length.

  • dict:

    • Dicts can be used to replace different values in different columns. For example, {‘a’: 1, ‘z’: 2} specifies that the value 1 in column a and the value 2 in column z should be replaced with replacement*.

valuenumeric, str, list-like, or dict

Value(s) to replace to_replace with. If a dict is provided, then its keys must match the keys in to_replace, and corresponding values must be compatible (e.g., if they are lists, then they must match in length).

inplacebool, default False

If True, in place.

Returns
resultDataFrame

DataFrame after replacement.

Notes

Parameters that are currently not supported are: limit, regex, method

Examples

>>> import cudf
>>> gdf = cudf.DataFrame()
>>> gdf['id']= [0, 1, 2, -1, 4, -1, 6]
>>> gdf['id']= gdf['id'].replace(-1, None)
>>> gdf
     id
0     0
1     1
2     2
3  null
4     4
5  null
6     6
reset_index(self, level=None, drop=False, inplace=False, col_level=0, col_fill='')

Reset the index.

Reset the index of the DataFrame, and use the default one instead.

Parameters
dropbool, default False

Do not try to insert index into dataframe columns. This resets the index to the default integer index.

inplacebool, default False

Modify the DataFrame in place (do not create a new object).

Returns
DataFrame or None

DataFrame with the new index or None if inplace=True.

Examples

>>> df = cudf.DataFrame([('bird', 389.0),
...                    ('bird', 24.0),
...                    ('mammal', 80.5),
...                    ('mammal', np.nan)],
...                   index=['falcon', 'parrot', 'lion', 'monkey'],
...                   columns=('class', 'max_speed'))
>>> df
        class max_speed
falcon    bird     389.0
parrot    bird      24.0
lion    mammal      80.5
monkey  mammal      null
>>> df.reset_index()
    index   class max_speed
0  falcon    bird     389.0
1  parrot    bird      24.0
2    lion  mammal      80.5
3  monkey  mammal      null
>>> df.reset_index(drop=True)
    class max_speed
0    bird     389.0
1    bird      24.0
2  mammal      80.5
3  mammal      null
rfloordiv(self, other, axis='columns', level=None, fill_value=None)

Get Integer division of dataframe and other, element-wise (binary operator rfloordiv).

Equivalent to other // dataframe, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, floordiv.

Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

# TODO: Add emaples

rmod(self, other, axis='columns', level=None, fill_value=None)

Get Modulo division 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: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [1, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> 100 % df
        angles  degrees
circle          0      100
triangle        1      100
rectangle       0      100
>>> df.rmod(100)
        angles  degrees
circle          0      100
triangle        1      100
rectangle       0      100
rmul(self, other, axis='columns', level=None, fill_value=None)

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: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> other = pd.DataFrame({'angles': [0, 3, 4]},
...                      index=['circle', 'triangle', 'rectangle'])
>>> other * df
        angles degrees
circle          0    null
triangle        9    null
rectangle      16    null
>>> df.rmul(other, fill_value=0)
        angles  degrees
circle          0        0
triangle        9        0
rectangle      16        0
rolling(self, window, min_periods=None, center=False, axis=0, win_type=None)

Rolling window calculations.

Parameters
windowint or offset

Size of the window, i.e., the number of observations used to calculate the statistic. For datetime indexes, an offset can be provided instead of an int. The offset must be convertible to a timedelta. As opposed to a fixed window size, each window will be sized to accommodate observations within the time period specified by the offset.

min_periodsint, optional

The minimum number of observations in the window that are required to be non-null, so that the result is non-null. If not provided or None, min_periods is equal to the window size.

centerbool, optional

If True, the result is set at the center of the window. If False (default), the result is set at the right edge of the window.

Returns
Rolling object.

Examples

>>> import cudf
>>> a = cudf.Series([1, 2, 3, None, 4])

Rolling sum with window size 2.

>>> print(a.rolling(2).sum())
0
1    3
2    5
3
4
dtype: int64

Rolling sum with window size 2 and min_periods 1.

>>> print(a.rolling(2, min_periods=1).sum())
0    1
1    3
2    5
3    3
4    4
dtype: int64

Rolling count with window size 3.

>>> print(a.rolling(3).count())
0    1
1    2
2    3
3    2
4    2
dtype: int64

Rolling count with window size 3, but with the result set at the center of the window.

>>> print(a.rolling(3, center=True).count())
0    2
1    3
2    2
3    2
4    1 dtype: int64

Rolling max with variable window size specified by an offset; only valid for datetime index.

>>> a = cudf.Series(
...     [1, 9, 5, 4, np.nan, 1],
...     index=[
...         pd.Timestamp('20190101 09:00:00'),
...         pd.Timestamp('20190101 09:00:01'),
...         pd.Timestamp('20190101 09:00:02'),
...         pd.Timestamp('20190101 09:00:04'),
...         pd.Timestamp('20190101 09:00:07'),
...         pd.Timestamp('20190101 09:00:08')
...     ]
... )
>>> print(a.rolling('2s').max())
2019-01-01T09:00:00.000    1
2019-01-01T09:00:01.000    9
2019-01-01T09:00:02.000    9
2019-01-01T09:00:04.000    4
2019-01-01T09:00:07.000
2019-01-01T09:00:08.000    1
dtype: int64

Apply custom function on the window with the apply method

>>> import numpy as np
>>> import math
>>> b = cudf.Series([16, 25, 36, 49, 64, 81], dtype=np.float64)
>>> def some_func(A):
...     b = 0
...     for a in A:
...         b = b + math.sqrt(a)
...     return b
...
>>> print(b.rolling(3, min_periods=1).apply(some_func))
0     4.0
1     9.0
2    15.0
3    18.0
4    21.0
5    24.0
dtype: float64

And this also works for window rolling set by an offset

>>> import pandas as pd
>>> c = cudf.Series(
...     [16, 25, 36, 49, 64, 81],
...     index=[
...          pd.Timestamp('20190101 09:00:00'),
...          pd.Timestamp('20190101 09:00:01'),
...          pd.Timestamp('20190101 09:00:02'),
...          pd.Timestamp('20190101 09:00:04'),
...          pd.Timestamp('20190101 09:00:07'),
...          pd.Timestamp('20190101 09:00:08')
...      ],
...     dtype=np.float64
... )
>>> print(c.rolling('2s').apply(some_func))
2019-01-01T09:00:00.000     4.0
2019-01-01T09:00:01.000     9.0
2019-01-01T09:00:02.000    11.0
2019-01-01T09:00:04.000     7.0
2019-01-01T09:00:07.000     8.0
2019-01-01T09:00:08.000    17.0
dtype: float64
rpow(self, other, axis='columns', level=None, fill_value=None)

Get Exponential power of dataframe and other, element-wise (binary operator pow).

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: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [1, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> 1 ** df
        angles  degrees
circle          1        1
triangle        1        1
rectangle       1        1
>>> df.rpow(1)
        angles  degrees
circle          1        1
triangle        1        1
rectangle       1        1
rsub(self, other, axis='columns', level=None, fill_value=None)

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: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df.rsub(1)
        angles  degrees
circle          1     -359
triangle       -2     -179
rectangle      -3     -359
>>> df.rsub([1, 2])
        angles  degrees
circle          1     -358
triangle       -2     -178
rectangle      -3     -358
rtruediv(self, other, axis='columns', level=None, fill_value=None)

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: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df.rtruediv(10)
            angles   degrees
circle          inf  0.027778
triangle   3.333333  0.055556
rectangle  2.500000  0.027778
>>> df.rdiv(10)
            angles   degrees
circle          inf  0.027778
triangle   3.333333  0.055556
rectangle  2.500000  0.027778
>>> 10 / df
            angles   degrees
circle          inf  0.027778
triangle   3.333333  0.055556
rectangle  2.500000  0.027778
select_dtypes(self, include=None, exclude=None)

Return a subset of the DataFrame’s columns based on the column dtypes.

Parameters
includestr or list

which columns to include based on dtypes

excludestr or list

which columns to exclude based on dtypes

set_index(self, index, drop=True)

Return a new DataFrame with a new index

Parameters
indexIndex, Series-convertible, str, or list of str

Index : the new index. Series-convertible : values for the new index. str : name of column to be used as series list of str : name of columns to be converted to a MultiIndex

dropboolean

whether to drop corresponding column for str index argument

property shape

Returns a tuple representing the dimensionality of the DataFrame.

skew(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Return unbiased Fisher-Pearson skew of a sample.

Parameters
skipna: bool, default True

Exclude NA/null values when computing the result.

Returns
Series

Notes

Parameters currently not supported are axis, level and numeric_only

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [3, 2, 3, 4], 'b': [7, 8, 10, 10]})
>>> df.skew()
a    0.00000
b   -0.37037
dtype: float64
sort_index(self, axis=0, level=None, ascending=True, inplace=False, kind=None, na_position='last', sort_remaining=True, ignore_index=False)

Sort object by labels (along an axis).

Parameters
axis{0 or ‘index’, 1 or ‘columns’}, default 0

The axis along which to sort. The value 0 identifies the rows, and 1 identifies the columns.

levelint or level name or list of ints or list of level names

If not None, sort on values in specified index level(s). This is only useful in the case of MultiIndex.

ascendingbool, default True

Sort ascending vs. descending.

inplacebool, default False

If True, perform operation in-place.

kindsorting method such as quick sort and others.

Not yet supported.

na_position{‘first’, ‘last’}, default ‘last’

Puts NaNs at the beginning if first; last puts NaNs at the end.

sort_remainingbool, default True

Not yet supported

ignore_indexbool, default False

if True, index will be replaced with RangeIndex.

Returns
DataFrame or None

Examples

>>> df = cudf.DataFrame(
... {"b":[3, 2, 1], "a":[2, 1, 3]}, index=[1, 3, 2])
>>> df.sort_index(axis=0)
   b  a
1  3  2
2  1  3
3  2  1
>>> df.sort_index(axis=1)
   a  b
1  2  3
3  1  2
2  3  1
sort_values(self, by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False)

Sort by the values row-wise.

Parameters
bystr or list of str

Name or list of names to sort by.

ascendingbool or list of bool, default True

Sort ascending vs. descending. Specify list for multiple sort orders. If this is a list of bools, must match the length of the by.

na_position{‘first’, ‘last’}, default ‘last’

‘first’ puts nulls at the beginning, ‘last’ puts nulls at the end

ignore_indexbool, default False

If True, index will not be sorted.

Returns
sorted_objcuDF DataFrame

Notes

Difference from pandas:
  • Support axis=’index’ only.

  • Not supporting: inplace, kind

Examples

>>> import cudf
>>> a = ('a', [0, 1, 2])
>>> b = ('b', [-3, 2, 0])
>>> df = cudf.DataFrame([a, b])
>>> print(df.sort_values('b'))
   a  b
0  0 -3
2  2  0
1  1  2
stack(self, level=- 1, dropna=True)

Stack the prescribed level(s) from columns to index

Return a reshaped Series

Parameters
dropnabool, default True

Whether to drop rows in the resulting Series with missing values.

Returns
The stacked cudf.Series

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a':[0,1,3], 'b':[1,2,4]})
>>> df.stack()
0  a    0
   b    1
1  a    1
   b    2
2  a    3
   b    4
dtype: int64
std(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs)

Return sample standard deviation of the DataFrame.

Normalized by N-1 by default. This can be changed using the ddof argument

Parameters
skipna: bool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

ddof: int, default 1

Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements.

Returns
Series

Notes

Parameters currently not supported are axis, level and numeric_only

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.std()
a    1.290994
b    1.290994
dtype: float64
sub(self, other, axis='columns', level=None, fill_value=None)

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: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df.sub(1)
        angles  degrees
circle         -1      359
triangle        2      179
rectangle       3      359
>>> df.sub([1, 2])
        angles  degrees
circle         -1      358
triangle        2      178
rectangle       3      358
sum(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, min_count=0, **kwargs)

Return sum of the values in the DataFrame.

Parameters
skipna: bool, default True

Exclude NA/null values when computing the result.

dtype: data type

Data type to cast the result to.

min_count: int, default 0

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.

The default being 0. This means the sum of an all-NA or empty Series is 0, and the product of an all-NA or empty Series is 1.

Returns
Series

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.sum()
a    10
b    34
dtype: int64
tail(self, n=5)

Returns the last n rows as a new DataFrame

Examples

>>> import cudf
>>> df = cudf.DataFrame()
>>> df['key'] = [0, 1, 2, 3, 4]
>>> df['val'] = [float(i + 10) for i in range(5)]  # insert column
>>> print(df.tail(2))
   key   val
3    3  13.0
4    4  14.0
take(self, positions, keep_index=True)

Return a new DataFrame containing the rows specified by positions

Parameters
positionsarray-like

Integer or boolean array-like specifying the rows of the output. If integer, each element represents the integer index of a row. If boolean, positions must be of the same length as self, and represents a boolean mask.

Returns
outDataFrame

New DataFrame

Examples

>>> a = cudf.DataFrame({'a': [1.0, 2.0, 3.0],
                        'b': pd.Series(['a', 'b', 'c'])})
>>> a.take([0, 2, 2])
     a  b
0  1.0  a
2  3.0  c
2  3.0  c
>>> a.take([True, False, True])
     a  b
0  1.0  a
2  3.0  c
to_arrow(self, preserve_index=True)

Convert to a PyArrow Table.

Examples

>>> import cudf
>>> a = ('a', [0, 1, 2])
>>> b = ('b', [-3, 2, 0])
>>> df = cudf.DataFrame([a, b])
>>> df.to_arrow()
pyarrow.Table
None: int64
a: int64
b: int64
to_csv(self, path=None, sep=',', na_rep='', columns=None, header=True, index=True, line_terminator='\n', chunksize=None)

Write a dataframe to csv file format.

Parameters
dfDataFrame

DataFrame object to be written to csv

pathstr, default None

Path of file where DataFrame will be written

sepchar, default ‘,’

Delimiter to be used.

na_repstr, default ‘’

String to use for null entries

columnslist of str, optional

Columns to write

headerbool, default True

Write out the column names

indexbool, default True

Write out the index as a column

line_terminatorchar, default ‘n’
chunksizeint or None, default None

Rows to write at a time

Notes

  • Follows the standard of Pandas csv.QUOTE_NONNUMERIC for all output.

  • If to_csv leads to memory errors consider setting the chunksize argument.

Examples

Write a dataframe to csv.

>>> import cudf
>>> filename = 'foo.csv'
>>> df = cudf.DataFrame({'x': [0, 1, 2, 3],
                         'y': [1.0, 3.3, 2.2, 4.4],
                         'z': ['a', 'b', 'c', 'd']})
>>> df = df.set_index([3, 2, 1, 0])
>>> df.to_csv(filename)
to_dlpack(self)

Converts a cuDF object into a DLPack tensor.

DLPack is an open-source memory tensor structure: dmlc/dlpack.

This function takes a cuDF object and converts it to a PyCapsule object which contains a pointer to a DLPack tensor. This function deep copies the data into the DLPack tensor from the cuDF object.

Parameters
cudf_objDataFrame, Series, Index, or Column
Returns
pycapsule_objPyCapsule

Output DLPack tensor pointer which is encapsulated in a PyCapsule object.

to_feather(self, path, *args, **kwargs)

Write a DataFrame to the feather format.

Parameters
pathstr

File path

to_gpu_matrix(self)

Convert to a numba gpu ndarray

Returns
numba gpu ndarray
to_hdf(self, path_or_buf, key, *args, **kwargs)

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.

For more information see the user guide.

Parameters
path_or_bufstr or pandas.HDFStore

File path or HDFStore object.

keystr

Identifier for the group in the store.

mode{‘a’, ‘w’, ‘r+’}, default ‘a’

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.

format{‘fixed’, ‘table’}, default ‘fixed’

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.

appendbool, default False

For Table formats, append the input data to the existing.

data_columnslist of columns or True, optional

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’.

complevel{0-9}, optional

Specifies a compression level for data. A value of 0 disables compression.

complib{‘zlib’, ‘lzo’, ‘bzip2’, ‘blosc’}, default ‘zlib’

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.

fletcher32bool, default False

If applying compression use the fletcher32 checksum.

dropnabool, default False

If true, ALL nan rows will not be written to store.

errorsstr, default ‘strict’

Specifies how encoding and decoding errors are to be handled. See the errors argument for open() for a full list of options.

See also

cudf.io.hdf.read_hdf

Read from HDF file.

cudf.io.parquet.to_parquet

Write a DataFrame to the binary parquet format.

cudf.io.feather.to_feather

Write out feather-format for DataFrames.

to_json(self, path_or_buf=None, *args, **kwargs)

Convert the cuDF object to a JSON string. Note nulls and NaNs will be converted to null and datetime objects will be converted to UNIX timestamps.

Parameters
path_or_bufstring or file handle, optional

File path or object. If not specified, the result is returned as a string.

orientstring

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, and the data component is like orient='records'.

date_format{None, ‘epoch’, ‘iso’}

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’.

double_precisionint, default 10

The number of decimal places to use when encoding floating point values.

force_asciibool, default True

Force encoded string to be ASCII.

date_unitstring, default ‘ms’ (milliseconds)

The time unit to encode to, governs timestamp and ISO8601 precision. One of ‘s’, ‘ms’, ‘us’, ‘ns’ for second, millisecond, microsecond, and nanosecond respectively.

default_handlercallable, default None

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 serializable object.

linesbool, default False

If ‘orient’ is ‘records’ write out line delimited json format. Will throw ValueError if incorrect ‘orient’ since others are not list like.

compression{‘infer’, ‘gzip’, ‘bz2’, ‘zip’, ‘xz’, None}

A string representing the compression to use in the output file, only used when the first argument is a filename. By default, the compression is inferred from the filename.

indexbool, default True

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’.

to_orc(self, fname, compression=None, *args, **kwargs)

Write a DataFrame to the ORC format.

Parameters
fnamestr

File path or object where the ORC dataset will be stored.

compression{{ ‘snappy’, None }}, default None

Name of the compression to use. Use None for no compression.

to_pandas(self)

Convert to a Pandas DataFrame.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [0, 1, 2], 'b': [-3, 2, 0]})
>>> pdf = df.to_pandas()
>>> pdf
   a  b
0  0 -3
1  1  2
2  2  0
>>> type(pdf)
<class 'pandas.core.frame.DataFrame'>
to_parquet(self, path, *args, **kwargs)

Write a DataFrame to the parquet format.

Parameters
pathstr

File path or Root Directory path. Will be used as Root Directory path while writing a partitioned dataset.

compression{‘snappy’, ‘gzip’, ‘brotli’, None}, default ‘snappy’

Name of the compression to use. Use None for no compression.

indexbool, default None

If True, include the dataframe’s index(es) in the file output. If False, they will not be written to the file. If None, the engine’s default behavior will be used.

partition_colslist, optional, default None

Column names by which to partition the dataset Columns are partitioned in the order they are given

to_records(self, index=True)

Convert to a numpy recarray

Parameters
indexbool

Whether to include the index in the output.

Returns
numpy recarray
to_string(self)

Convert to string

cuDF uses Pandas internals for efficient string formatting. Set formatting options using pandas string formatting options and cuDF objects will print identically to Pandas objects.

cuDF supports null/None as a value in any column type, which is transparently supported during this output process.

Examples

>>> import cudf
>>> df = cudf.DataFrame()
>>> df['key'] = [0, 1, 2]
>>> df['val'] = [float(i + 10) for i in range(3)]
>>> df.to_string()
'   key   val\n0    0  10.0\n1    1  11.0\n2    2  12.0'
transpose(self)

Transpose index and columns.

Returns
a new (ncol x nrow) dataframe. self is (nrow x ncol)

Notes

Difference from pandas: Not supporting copy because default and only behavior is copy=True

truediv(self, other, axis='columns', level=None, fill_value=None)

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: +, -, *, /, //, %, **.

Parameters
otherscalar, sequence, Series, or DataFrame

Any single or multiple element data structure, or list-like object.

fill_valuefloat or None, default None

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.

Returns
DataFrame

Result of the arithmetic operation.

Examples

>>> import cudf
>>> df = cudf.DataFrame({'angles': [0, 3, 4],
...                    'degrees': [360, 180, 360]},
...                   index=['circle', 'triangle', 'rectangle'])
>>> df.truediv(10)
            angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0
>>> df.div(10)
            angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0
>>> df / 10
            angles  degrees
circle        0.0     36.0
triangle      0.3     18.0
rectangle     0.4     36.0
property values

Return a CuPy representation of the DataFrame.

Only the values in the DataFrame will be returned, the axes labels will be removed.

Returns
out: cupy.ndarray

The values of the DataFrame.

var(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs)

Return unbiased variance of the DataFrame.

Normalized by N-1 by default. This can be changed using the ddof argument

Parameters
skipna: bool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

ddof: int, default 1

Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements.

Returns
scalar

Notes

Parameters currently not supported are axis, level and numeric_only

Examples

>>> import cudf
>>> df = cudf.DataFrame({'a': [1, 2, 3, 4], 'b': [7, 8, 9, 10]})
>>> df.var()
a    1.666667
b    1.666667
dtype: float64
cudf.core.reshape.concat(objs, axis=0, ignore_index=False, sort=None)

Concatenate DataFrames, Series, or Indices row-wise.

Parameters
objslist of DataFrame, Series, or Index
axis{0/’index’, 1/’columns’}, default 0

The axis to concatenate along.

ignore_indexbool, default False

Set True to ignore the index of the objs and provide a default range index instead.

Returns
A new object of like type with rows from each object in objs.
cudf.core.reshape.get_dummies(df, prefix=None, prefix_sep='_', dummy_na=False, columns=None, cats={}, sparse=False, drop_first=False, dtype='int8')

Returns a dataframe whose columns are the one hot encodings of all columns in df

Parameters
dfcudf.DataFrame

dataframe to encode

prefixstr, dict, or sequence, optional

prefix to append. Either a str (to apply a constant prefix), dict mapping column names to prefixes, or sequence of prefixes to apply with the same length as the number of columns. If not supplied, defaults to the empty string

prefix_sepstr, dict, or sequence, optional, default ‘_’

separator to use when appending prefixes

dummy_naboolean, optional

Right now this is NON-FUNCTIONAL argument in rapids.

catsdict, optional

dictionary mapping column names to sequences of integers representing that column’s category. See cudf.DataFrame.one_hot_encoding for more information. if not supplied, it will be computed

sparseboolean, optional

Right now this is NON-FUNCTIONAL argument in rapids.

drop_firstboolean, optional

Right now this is NON-FUNCTIONAL argument in rapids.

columnssequence of str, optional

Names of columns to encode. If not provided, will attempt to encode all columns. Note this is different from pandas default behavior, which encodes all columns with dtype object or categorical

dtypestr, optional

output dtype, default ‘int8’

cudf.core.reshape.melt(frame, id_vars=None, value_vars=None, var_name=None, value_name='value', col_level=None)

Unpivots a DataFrame from wide format to long format, optionally leaving identifier variables set.

Parameters
frameDataFrame
id_varstuple, list, or ndarray, optional

Column(s) to use as identifier variables. default: None

value_varstuple, list, or ndarray, optional

Column(s) to unpivot. default: all columns that are not set as id_vars.

var_namescalar

Name to use for the variable column. default: frame.columns.name or ‘variable’

value_namestr

Name to use for the value column. default: ‘value’

Returns
outDataFrame

Melted result

Difference from pandas:
  • Does not support ‘col_level’ because cuDF does not have multi-index

Examples

>>> import cudf
>>> import numpy as np
>>> df = cudf.DataFrame({'A': {0: 1, 1: 1, 2: 5},
...                      'B': {0: 1, 1: 3, 2: 6},
...                      'C': {0: 1.0, 1: np.nan, 2: 4.0},
...                      'D': {0: 2.0, 1: 5.0, 2: 6.0}})
>>> cudf.melt(frame=df, id_vars=['A', 'B'], value_vars=['C', 'D'])
     A    B variable value
0    1    1        C   1.0
1    1    3        C
2    5    6        C   4.0
3    1    1        D   2.0
4    1    3        D   5.0
5    5    6        D   6.0
cudf.core.reshape.merge_sorted(objs, keys=None, by_index=False, ignore_index=False, ascending=True, na_position='last')

Merge a list of sorted DataFrame or Series objects.

Dataframes/Series in objs list MUST be pre-sorted by columns listed in keys, or by the index (if by_index=True).

Parameters
objslist of DataFrame, Series, or Index
keyslist, default None

List of Column names to sort by. If None, all columns used (Ignored if index=True)

by_indexbool, default False

Use index for sorting. keys input will be ignored if True

ignore_indexbool, default False

Drop and ignore index during merge. Default range index will be used in the output dataframe.

ascendingbool, default True

Sorting is in ascending order, otherwise it is descending

na_position{‘first’, ‘last’}, default ‘last’

‘first’ nulls at the beginning, ‘last’ nulls at the end

Returns
A new, lexicographically sorted, DataFrame/Series.

Series

class cudf.core.series.Series(data=None, index=None, dtype=None, name=None, nan_as_null=True)

One-dimensional GPU array (including time series).

Labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Statistical methods from ndarray have been overridden to automatically exclude missing data (currently represented as null/NaN).

Operations between Series (+, -, /, , *) align values based on their associated index values– they need not be the same length. The result index will be the sorted union of the two indexes.

Series objects are used as columns of DataFrame.

Parameters
dataarray-like, Iterable, dict, or scalar value

Contains data stored in Series.

indexarray-like or Index (1d)

Values must be hashable and have the same length as data. Non-unique index values are allowed. Will default to RangeIndex (0, 1, 2, …, n) if not provided. If both a dict and index sequence are used, the index will override the keys found in the dict.

dtypestr, numpy.dtype, or ExtensionDtype, optional

Data type for the output Series. If not specified, this will be inferred from data.

namestr, optional

The name to give to the Series.

nan_as_nullbool, Default True

If None/True, converts np.nan values to null values. If False, leaves np.nan values as is.

Attributes
cat

Accessor object for categorical properties of the Series values.

data

The gpu buffer for the data

dt

Accessor object for datetimelike properties of the Series values.

dtype

dtype of the Series

empty

Indicator whether Series is empty.

has_nulls

Indicator whether Series contains null values.

iloc

Select values by position.

index

The index object

is_monotonic

Return boolean if values in the object are monotonic_increasing.

is_monotonic_decreasing

Return boolean if values in the object are monotonic_decreasing.

is_monotonic_increasing

Return boolean if values in the object are monotonic_increasing.

is_unique

Return boolean if values in the object are unique.

loc

Select values by label.

name

Returns name of the Series.

ndim

Dimension of the data.

null_count

Number of null values

nullable

A boolean indicating whether a null-mask is needed

nullmask

The gpu buffer for the null-mask

shape

Returns a tuple representing the dimensionality of the Series.

str

Vectorized string functions for Series and Index.

valid_count

Number of non-null values

values

Return a CuPy representation of the Series.

values_host

Return a numpy representation of the Series.

Methods

abs(self)

Absolute value of each element of the series.

add(self, other[, fill_value, axis])

Addition of series and other, element-wise (binary operator add).

all(self[, axis, bool_only, skipna, level])

Return whether all elements are True in Series.

any(self[, axis, bool_only, skipna, level])

Return whether any elements is True in Series.

append(self, other[, ignore_index])

Append values from another Series or array-like object.

applymap(self, udf[, out_dtype])

Apply an elementwise function to transform the values in the Column.

argsort(self[, ascending, na_position])

Returns a Series of int64 index that will sort the series.

as_index(self)

Returns a new Series with a RangeIndex.

as_mask(self)

Convert booleans to bitmask

astype(self, dtype[, copy, errors])

Cast the Series to the given dtype

ceil(self)

Rounds each value upward to the smallest integral value not less than the original.

copy(self[, deep])

Make a copy of this object’s indices and data.

corr(self, other[, method, min_periods])

Calculates the sample correlation between two Series, excluding missing values.

count(self[, level])

Return number of non-NA/null observations in the Series

cov(self, other[, min_periods])

Compute covariance with Series, excluding missing values.

cummax(self[, axis, skipna])

Return cumulative maximum of the Series.

cummin(self[, axis, skipna])

Return cumulative minimum of the Series.

cumprod(self[, axis, skipna])

Return cumulative product of the Series.

cumsum(self[, axis, skipna])

Return cumulative sum of the Series.

describe(self[, percentiles, include, exclude])

Compute summary statistics of a Series.

diff(self[, periods])

Calculate the difference between values at positions i and i - N in an array and store the output in a new array.

digitize(self, bins[, right])

Return the indices of the bins to which each value in series belongs.

drop_duplicates(self[, keep, inplace, …])

Return Series with duplicate values removed

dropna(self)

Return a Series with null values removed.

eq(self, other[, fill_value, axis])

Equal to of series and other, element-wise (binary operator eq).

equals(self, other)

Test whether two objects contain the same elements.

factorize(self[, na_sentinel])

Encode the input values as integer labels

fillna(self, value[, method, axis, inplace, …])

Fill null values with value without changing the series’ type.

floor(self)

Rounds each value downward to the largest integral value not greater than the original.

floordiv(self, other[, fill_value, axis])

Integer division of series and other, element-wise (binary operator floordiv).

from_arrow(s)

Convert from a PyArrow Array.

from_categorical(categorical[, codes])

Creates from a pandas.Categorical

from_masked_array(data, mask[, null_count])

Create a Series with null-mask.

from_pandas(s[, nan_as_null])

Convert from a Pandas Series.

ge(self, other[, fill_value, axis])

Greater than or equal to of series and other, element-wise (binary operator ge).

groupby(self[, by, group_series, level, …])

Group Series using a mapper or by a Series of columns.

gt(self, other[, fill_value, axis])

Greater than of series and other, element-wise (binary operator gt).

hash_encode(self, stop[, use_name])

Encode column values as ints in [0, stop) using hash function.

hash_values(self)

Compute the hash of values in this column.

head(self[, n])

Return the first n rows.

isin(self, values)

Check whether values are contained in Series.

kurt(self[, axis, skipna, level, numeric_only])

Return Fisher’s unbiased kurtosis of a sample.

kurtosis(self[, axis, skipna, level, …])

Return Fisher’s unbiased kurtosis of a sample.

label_encoding(self, cats[, dtype, na_sentinel])

Perform label encoding

le(self, other[, fill_value, axis])

Less than or equal to of series and other, element-wise (binary operator le).

lt(self, other[, fill_value, axis])

Less than of series and other, element-wise (binary operator lt).

max(self[, axis, skipna, dtype, level, …])

Return the maximum of the values in the Series.

mean(self[, axis, skipna, level, numeric_only])

Return the mean of the values in the series.

median(self[, skipna])

Compute the median of the series

memory_usage(self[, index, deep])

Return the memory usage of the Series.

min(self[, axis, skipna, dtype, level, …])

Return the minimum of the values in the Series.

mod(self, other[, fill_value, axis])

Modulo of series and other, element-wise (binary operator mod).

mul(self, other[, fill_value, axis])

Multiplication of series and other, element-wise (binary operator mul).

nans_to_nulls(self)

Convert nans (if any) to nulls

ne(self, other[, fill_value, axis])

Not equal to of series and other, element-wise (binary operator ne).

nlargest(self[, n, keep])

Returns a new Series of the n largest element.

nsmallest(self[, n, keep])

Returns a new Series of the n smallest element.

nunique(self[, method, dropna])

Returns the number of unique values of the Series: approximate version, and exact version to be moved to libgdf

one_hot_encoding(self, cats[, dtype])

Perform one-hot-encoding

pow(self, other[, fill_value, axis])

Exponential power of series and other, element-wise (binary operator pow).

prod(self[, axis, skipna, dtype, level, …])

Return product of the values in the series

product(self[, axis, skipna, dtype, level, …])

Return product of the values in the Series.

quantile(self[, q, interpolation, exact, …])

Return values at the given quantile.

radd(self, other[, fill_value, axis])

Addition of series and other, element-wise (binary operator radd).

reindex(self[, index, copy])

Return a Series that conforms to a new index

rename(self[, index, copy])

Alter Series name

replace(self[, to_replace, value, inplace, …])

Replace values given in to_replace with value.

reset_index(self[, drop, inplace])

Reset index to RangeIndex

reverse(self)

Reverse the Series

rfloordiv(self, other[, fill_value, axis])

Integer division of series and other, element-wise (binary operator rfloordiv).

rmod(self, other[, fill_value, axis])

Modulo of series and other, element-wise (binary operator rmod).

rmul(self, other[, fill_value, axis])

Multiplication of series and other, element-wise (binary operator rmul).

rolling(self, window[, min_periods, center, …])

Rolling window calculations.

round(self[, decimals])

Round a Series to a configurable number of decimal places.

rpow(self, other[, fill_value, axis])

Exponential power of series and other, element-wise (binary operator rpow).

rsub(self, other[, fill_value, axis])

Subtraction of series and other, element-wise (binary operator rsub).

rtruediv(self, other[, fill_value, axis])

Floating division of series and other, element-wise (binary operator rtruediv).

scale(self)

Scale values to [0, 1] in float64

set_index(self, index)

Returns a new Series with a different index.

set_mask(self, mask[, null_count])

Create new Series by setting a mask array.

skew(self[, axis, skipna, level, numeric_only])

Return unbiased Fisher-Pearson skew of a sample.

sort_index(self[, ascending])

Sort by the index.

sort_values(self[, axis, ascending, …])

Sort by the values.

std(self[, axis, skipna, level, ddof, …])

Return sample standard deviation of the Series.

sub(self, other[, fill_value, axis])

Subtraction of series and other, element-wise (binary operator sub).

sum(self[, axis, skipna, dtype, level, …])

Return sum of the values in the Series.

tail(self[, n])

Returns the last n rows as a new Series

take(self, indices[, keep_index])

Return Series by taking values from the corresponding indices.

to_array(self[, fillna])

Get a dense numpy array for the data.

to_arrow(self)

Convert Series to a PyArrow Array.

to_dlpack(self)

Converts a cuDF object into a DLPack tensor.

to_frame(self[, name])

Convert Series into a DataFrame

to_gpu_array(self[, fillna])

Get a dense numba device array for the data.

to_hdf(self, path_or_buf, key, *args, **kwargs)

Write the contained data to an HDF5 file using HDFStore.

to_json(self[, path_or_buf])

Convert the cuDF object to a JSON string.

to_pandas(self[, index])

Convert to a Pandas Series.

to_string(self)

Convert to string

tolist(self)

Return a list type from series data.

truediv(self, other[, fill_value, axis])

Floating division of series and other, element-wise (binary operator truediv).

unique(self)

Returns unique values of this Series.

value_counts(self[, normalize, sort, …])

Return a Series containing counts of unique values.

values_to_string(self[, nrows])

Returns a list of string for each element.

var(self[, axis, skipna, level, ddof, …])

Return unbiased variance of the Series.

abs(self)

Absolute value of each element of the series.

Returns a new Series.

add(self, other, fill_value=None, axis=0)

Addition of series and other, element-wise (binary operator add).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs)

Return whether all elements are True in Series.

Parameters
skipnabool, default True

Exclude NA/null values. If the entire row/column is NA and skipna is True, then the result will be True, as for an empty row/column. If skipna is False, then NA are treated as True, because these are not equal to zero.

Returns
scalar

Notes

Parameters currently not supported are axis, bool_only, level.

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.all()
True
any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs)

Return whether any elements is True in Series.

Parameters
skipnabool, default True

Exclude NA/null values. If the entire row/column is NA and skipna is True, then the result will be False, as for an empty row/column. If skipna is False, then NA are treated as True, because these are not equal to zero.

Returns
scalar

Notes

Parameters currently not supported are axis, bool_only, level.

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.any()
True
append(self, other, ignore_index=False)

Append values from another Series or array-like object. If ignore_index=True, the index is reset.

Parameters
otherSeries or array-like object
ignore_indexboolean, default False. If true, the index is reset.
Returns
A new Series equivalent to self concatenated with other
applymap(self, udf, out_dtype=None)

Apply an elementwise function to transform the values in the Column.

The user function is expected to take one argument and return the result, which will be stored to the output Series. The function cannot reference globals except for other simple scalar objects.

Parameters
udffunction

Either a callable python function or a python function already decorated by numba.cuda.jit for call on the GPU as a device

out_dtypenumpy.dtype; optional

The dtype for use in the output. Only used for numba.cuda.jit decorated udf. By default, the result will have the same dtype as the source.

Returns
resultSeries

The mask and index are preserved.

Notes

The supported Python features are listed in

with these exceptions:

  • Math functions in cmath are not supported since libcudf does not have complex number support and output of cmath functions are most likely complex numbers.

  • These five functions in math are not supported since numba generates multiple PTX functions from them

    • math.sin()

    • math.cos()

    • math.tan()

    • math.gamma()

    • math.lgamma()

  • Series with string dtypes are not supported in applymap method.

  • Global variables need to be re-defined explicitly inside the udf, as numba considers them to be compile-time constants and there is no known way to obtain value of the global variable.

Examples

Returning a Series of booleans using only a literal pattern.

>>> import cudf
>>> s = cudf.Series([1, 10, -10, 200, 100])
>>> s.applymap(lambda x: x)
0      1
1     10
2    -10
3    200
4    100
dtype: int64
>>> s.applymap(lambda x: x in [1, 100, 59])
0     True
1    False
2    False
3    False
4     True
dtype: bool
>>> s.applymap(lambda x: x ** 2)
0        1
1      100
2      100
3    40000
4    10000
dtype: int64
>>> s.applymap(lambda x: (x ** 2) + (x / 2))
0        1.5
1      105.0
2       95.0
3    40100.0
4    10050.0
dtype: float64
>>> def cube_function(a):
...     return a ** 3
...
>>> s.applymap(cube_function)
0          1
1       1000
2      -1000
3    8000000
4    1000000
dtype: int64
>>> def custom_udf(x):
...     if x > 0:
...         return x + 5
...     else:
...         return x - 5
...
>>> s.applymap(custom_udf)
0      6
1     15
2    -15
3    205
4    105
dtype: int64
argsort(self, ascending=True, na_position='last')

Returns a Series of int64 index that will sort the series.

Uses Thrust sort.

Returns
result: Series
as_index(self)

Returns a new Series with a RangeIndex.

Examples

>>> s = cudf.Series([1,2,3], index=['a','b','c'])
>>> s
a    1
b    2
c    3
dtype: int64
>>> s.as_index()
0    1
1    2
2    3
dtype: int64
as_mask(self)

Convert booleans to bitmask

Returns
device array
astype(self, dtype, copy=False, errors='raise')

Cast the Series to the given dtype

Parameters
dtypedata type, or dict of column name -> data type

Use a numpy.dtype or Python type to cast Series object to the same type. Alternatively, use {col: dtype, …}, where col is a series name and dtype is a numpy.dtype or Python type to cast to.

copybool, default False

Return a deep-copy when copy=True. Note by default copy=False setting is used and hence changes to values then may propagate to other cudf objects.

errors{‘raise’, ‘ignore’, ‘warn’}, default ‘raise’

Control raising of exceptions on invalid data for provided dtype. - raise : allow exceptions to be raised - ignore : suppress exceptions. On error return original object. - warn : prints last exceptions as warnings and return original object.

Returns
outSeries

Returns self.copy(deep=copy) if dtype is the same as self.dtype.

property cat

Accessor object for categorical properties of the Series values. Be aware that assigning to categories is a inplace operation, while all methods return new categorical data per default.

Parameters
dataSeries or CategoricalIndex

Examples

>>> s = cudf.Series([1,2,3], dtype='category')
>>> s
>>> s
0    1
1    2
2    3
dtype: category
Categories (3, int64): [1, 2, 3]
>>> s.cat.categories
Int64Index([1, 2, 3], dtype='int64')
>>> s.cat.reorder_categories([3,2,1])
0    1
1    2
2    3
dtype: category
Categories (3, int64): [3, 2, 1]
>>> s.cat.remove_categories([1])
0   null
1      2
2      3
dtype: category
Categories (2, int64): [2, 3]
>>> s.cat.set_categories(list('abcde'))
0   null
1   null
2   null
dtype: category
Categories (5, object): [a, b, c, d, e]
>>> s.cat.as_ordered()
0    1
1    2
2    3
dtype: category
Categories (3, int64): [1 < 2 < 3]
>>> s.cat.as_unordered()
0    1
1    2
2    3
dtype: category
Categories (3, int64): [1, 2, 3]
ceil(self)

Rounds each value upward to the smallest integral value not less than the original.

Returns a new Series.

copy(self, deep=True)

Make a copy of this object’s indices and data.

When deep=True (default), a new object will be created with a copy of the calling object’s data and indices. Modifications to the data or indices of the copy will not be reflected in the original object (see notes below). When deep=False, a new object will be created without copying the calling object’s data or index (only references to the data and index are copied). Any changes to the data of the original will be reflected in the shallow copy (and vice versa).

Parameters
deepbool, default True

Make a deep copy, including a copy of the data and the indices. With deep=False neither the indices nor the data are copied.

Returns
copySeries or DataFrame

Object type matches caller.

Examples

>>> s = cudf.Series([1, 2], index=["a", "b"])
>>> s
a    1
b    2
dtype: int64
>>> s_copy = s.copy()
>>> s_copy
a    1
b    2
dtype: int64

Shallow copy versus default (deep) copy:

>>> s = cudf.Series([1, 2], index=["a", "b"])
>>> deep = s.copy()
>>> shallow = s.copy(deep=False)

Shallow copy shares data and index with original.

>>> s is shallow
False
>>> s._column is shallow._column and s.index is shallow.index
True

Deep copy has own copy of data and index.

>>> s is deep
False
>>> s.values is deep.values or s.index is deep.index
False

Updates to the data shared by shallow copy and original is reflected in both; deep copy remains unchanged.

>>> s['a'] = 3
>>> shallow['b'] = 4
>>> s
a    3
b    4
dtype: int64
>>> shallow
a    3
b    4
dtype: int64
>>> deep
a    1
b    2
dtype: int64
corr(self, other, method='pearson', min_periods=None)

Calculates the sample correlation between two Series, excluding missing values.

Examples

>>> import cudf
>>> ser1 = cudf.Series([0.9, 0.13, 0.62])
>>> ser2 = cudf.Series([0.12, 0.26, 0.51])
>>> ser1.corr(ser2)
-0.20454263717316112
count(self, level=None, **kwargs)

Return number of non-NA/null observations in the Series

Returns
int

Number of non-null values in the Series.

Notes

Parameters currently not supported is level.

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.count()
5
cov(self, other, min_periods=None)

Compute covariance with Series, excluding missing values.

Parameters
otherSeries

Series with which to compute the covariance.

Returns
float

Covariance between Series and other normalized by N-1 (unbiased estimator).

Notes

min_periods parameter is not yet supported.

Examples

>>> import cudf
>>> ser1 = cudf.Series([0.9, 0.13, 0.62])
>>> ser2 = cudf.Series([0.12, 0.26, 0.51])
>>> ser1.cov(ser2)
-0.015750000000000004
cummax(self, axis=0, skipna=True, *args, **kwargs)

Return cumulative maximum of the Series.

Parameters
skipnabool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

Returns
Series

Notes

Parameters currently not supported is axis

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.cummax()
0    1
1    5
2    5
3    5
4    5
cummin(self, axis=None, skipna=True, *args, **kwargs)

Return cumulative minimum of the Series.

Parameters
skipnabool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

Returns
Series

Notes

Parameters currently not supported is axis

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.cummin()
0    1
1    1
2    1
3    1
4    1
cumprod(self, axis=0, skipna=True, *args, **kwargs)

Return cumulative product of the Series.

Parameters
skipnabool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

Returns
Series

Notes

Parameters currently not supported is axis

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.cumprod()
0    1
1    5
2    10
3    40
4    120
cumsum(self, axis=0, skipna=True, *args, **kwargs)

Return cumulative sum of the Series.

Parameters
skipnabool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

Returns
Series

Notes

Parameters currently not supported is axis

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.cumsum()
0    1
1    6
2    8
3    12
4    15
property data

The gpu buffer for the data

describe(self, percentiles=None, include=None, exclude=None)

Compute summary statistics of a Series. For numeric data, the output includes the minimum, maximum, mean, median, standard deviation, and various quantiles. For object data, the output includes the count, number of unique values, the most common value, and the number of occurrences of the most common value.

Parameters
percentileslist-like, optional

The percentiles used to generate the output summary statistics. If None, the default percentiles used are the 25th, 50th and 75th. Values should be within the interval [0, 1].

Returns
A DataFrame containing summary statistics of relevant columns from
the input DataFrame.

Examples

Describing a Series containing numeric values.

>>> import cudf
>>> s = cudf.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
>>> print(s.describe())
   stats   values
0  count     10.0
1   mean      5.5
2    std  3.02765
3    min      1.0
4    25%      2.5
5    50%      5.5
6    75%      7.5
7    max     10.0
diff(self, periods=1)

Calculate the difference between values at positions i and i - N in an array and store the output in a new array.

Notes

Diff currently only supports float and integer dtype columns with no null values.

digitize(self, bins, right=False)

Return the indices of the bins to which each value in series belongs.

Parameters
binsnp.array

1-D monotonically, increasing array with same type as this series.

rightbool

Indicates whether interval contains the right or left bin edge.

Returns
A new Series containing the indices.

Notes

Monotonicity of bins is assumed and not checked.

drop_duplicates(self, keep='first', inplace=False, ignore_index=False)

Return Series with duplicate values removed

dropna(self)

Return a Series with null values removed.

property dt

Accessor object for datetimelike properties of the Series values.

Returns
A Series indexed like the original Series.
Raises
TypeError if the Series does not contain datetimelike values.

Examples

>>> s.dt.hour
>>> s.dt.second
>>> s.dt.day
property dtype

dtype of the Series

property empty

Indicator whether Series is empty.

True if Series is entirely empty (no items).

Returns
outbool

If Series is empty, return True, if not return False.

eq(self, other, fill_value=None, axis=0)

Equal to of series and other, element-wise (binary operator eq).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

equals(self, other)

Test whether two objects contain the same elements. This function allows two Series or DataFrames to be compared against each other to see if they have the same shape and elements. NaNs in the same location are considered equal. The column headers do not need to have the same type.

Parameters
otherSeries or DataFrame

The other Series or DataFrame to be compared with the first.

Returns
bool

True if all elements are the same in both objects, False otherwise.

Examples

>>> import cudf
>>> s = cudf.Series([1, 2, 3])
>>> other = cudf.Series([1, 2, 3])
>>> s.equals(other)
True
>>> different = cudf.Series([1.5, 2, 3])
>>> s.equals(different)
False
factorize(self, na_sentinel=- 1)

Encode the input values as integer labels

Parameters
na_sentinelnumber

Value to indicate missing category.

Returns
(labels, cats)(Series, Series)
  • labels contains the encoded values

  • cats contains the categories in order that the N-th item corresponds to the (N-1) code.

fillna(self, value, method=None, axis=None, inplace=False, limit=None)

Fill null values with value without changing the series’ type.

Parameters
valuescalar or Series-like

Value to use to fill nulls. If value’s dtype differs from the series, the fill value will be cast to the column’s dtype before applying the fill. If Series-like, null values are filled with the values in corresponding indices of the given Series.

Returns
resultSeries

Copy with nulls filled.

floor(self)

Rounds each value downward to the largest integral value not greater than the original.

Returns a new Series.

floordiv(self, other, fill_value=None, axis=0)

Integer division of series and other, element-wise (binary operator floordiv).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

classmethod from_arrow(s)

Convert from a PyArrow Array.

Parameters
sPyArrow Object

PyArrow Object which has to be converted to cudf Series.

Raises
TypeError for invalid input type.

Examples

>>> import pyarrow as pa
>>> import cudf
>>> import pyarrow as pa
>>> data = pa.array([1, 2, 3])
>>> data
<pyarrow.lib.Int64Array object at 0x7f67007e07c0>
[
1,
2,
3
]
>>> cudf.Series.from_arrow(data)
0    1
1    2
2    3
dtype: int64
classmethod from_categorical(categorical, codes=None)

Creates from a pandas.Categorical

If codes is defined, use it instead of categorical.codes

classmethod from_masked_array(data, mask, null_count=None)

Create a Series with null-mask. This is equivalent to:

Series(data).set_mask(mask, null_count=null_count)

Parameters
data1D array-like

The values. Null values must not be skipped. They can appear as garbage values.

mask1D array-like

The null-mask. Valid values are marked as 1; otherwise 0. The mask bit given the data index idx is computed as:

(mask[idx // 8] >> (idx % 8)) & 1
null_countint, optional

The number of null values. If None, it is calculated automatically.

classmethod from_pandas(s, nan_as_null=None)

Convert from a Pandas Series.

Parameters
sPandas Series object

A Pandas Series object which has to be converted to cuDF Series.

nan_as_nullbool, Default None

If None/True, converts np.nan values to null values. If False, leaves np.nan values as is.

Raises
TypeError for invalid input type.

Examples

>>> import cudf
>>> import pandas as pd
>>> import numpy as np
>>> data = [10, 20, 30, np.nan]
>>> pds = pd.Series(data)
>>> cudf.Series.from_pandas(pds)
0    10.0
1    20.0
2    30.0
3    null
dtype: float64
>>> cudf.Series.from_pandas(pds, nan_as_null=False)
0    10.0
1    20.0
2    30.0
3     NaN
dtype: float64
ge(self, other, fill_value=None, axis=0)

Greater than or equal to of series and other, element-wise (binary operator ge).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

groupby(self, by=None, group_series=None, level=None, sort=True, group_keys=True, as_index=None, dropna=True, method=None)

Group Series using a mapper or by a Series of columns.

A groupby operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group large amounts of data and compute operations on these groups.

Parameters
bymapping, function, label, or list of labels

Used to determine the groups for the groupby. If by is a function, it’s called on each value of the object’s index. If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups (the Series’ values are first aligned; see .align() method). If an cupy array is passed, the values are used as-is determine the groups. A label or list of labels may be passed to group by the columns in self. Notice that a tuple is interpreted as a (single) key.

levelint, level name, or sequence of such, default None

If the axis is a MultiIndex (hierarchical), group by a particular level or levels.

as_indexbool, default True

For aggregated output, return object with group labels as the index. Only relevant for DataFrame input. as_index=False is effectively “SQL-style” grouped output.

sortbool, default True

Sort group keys. Get better performance by turning this off. Note this does not influence the order of observations within each group. Groupby preserves the order of rows within each group.

Returns
SeriesGroupBy

Returns a groupby object that contains information about the groups.

Examples

>>> ser = cudf.Series([390., 350., 30., 20.],
...                 index=['Falcon', 'Falcon', 'Parrot', 'Parrot'],
...                 name="Max Speed")
>>> ser
Falcon    390.0
Falcon    350.0
Parrot     30.0
Parrot     20.0
Name: Max Speed, dtype: float64
>>> ser.groupby(level=0).mean()
Falcon    370.0
Parrot     25.0
Name: Max Speed, dtype: float64
>>> ser.groupby(ser > 100).mean()
Max Speed
False     25.0
True     370.0
Name: Max Speed, dtype: float64
gt(self, other, fill_value=None, axis=0)

Greater than of series and other, element-wise (binary operator gt).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

property has_nulls

Indicator whether Series contains null values.

Returns
outbool

If Series has atleast one null value, return True, if not return False.

hash_encode(self, stop, use_name=False)

Encode column values as ints in [0, stop) using hash function.

Parameters
stopint

The upper bound on the encoding range.

use_namebool

If True then combine hashed column values with hashed column name. This is useful for when the same values in different columns should be encoded with different hashed values.

Returns
resultSeries

The encoded Series.

hash_values(self)

Compute the hash of values in this column.

head(self, n=5)

Return the first n rows. This function returns the first n rows for the object based on position. It is useful for quickly testing if your object has the right type of data in it. For negative values of n, this function returns all rows except the last n rows, equivalent to df[:-n].

Parameters
nint, default 5

Number of rows to select.

Returns
same type as caller

The first n rows of the caller object.

See also

Series.tail

Returns the last n rows.

Examples

>>> ser = cudf.Series(['alligator', 'bee', 'falcon', 'lion', 'monkey', 'parrot', 'shark', 'whale', 'zebra'])        # noqa E501
>>> ser
0    alligator
1          bee
2       falcon
3         lion
4       monkey
5       parrot
6        shark
7        whale
8        zebra
dtype: object

Viewing the first 5 lines

>>> ser.head()
0    alligator
1          bee
2       falcon
3         lion
4       monkey
dtype: object

Viewing the first n lines (three in this case)

>>> ser.head(3)
0    alligator
1          bee
2       falcon
dtype: object

For negative values of n

>>> ser.head(-3)
0    alligator
1          bee
2       falcon
3         lion
4       monkey
5       parrot
dtype: object
property iloc

Select values by position.

See also

cudf.core.dataframe.Dataframe.iloc
property index

The index object

property is_monotonic

Return boolean if values in the object are monotonic_increasing.

Returns
outbool
property is_monotonic_decreasing

Return boolean if values in the object are monotonic_decreasing.

Returns
outbool
property is_monotonic_increasing

Return boolean if values in the object are monotonic_increasing.

Returns
outbool
property is_unique

Return boolean if values in the object are unique.

Returns
outbool
isin(self, values)

Check whether values are contained in Series.

Parameters
valuesset or list-like

The sequence of values to test. Passing in a single string will raise a TypeError. Instead, turn a single string into a list of one element.

Returns
resultSeries

Series of booleans indicating if each element is in values.

Raises
TypeError

If values is a string

kurt(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Return Fisher’s unbiased kurtosis of a sample.

Kurtosis obtained using Fisher’s definition of kurtosis (kurtosis of normal == 0.0). Normalized by N-1.

Parameters
skipnabool, default True

Exclude NA/null values when computing the result.

Returns
scalar

Notes

Parameters currently not supported are axis, level and numeric_only

kurtosis(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Return Fisher’s unbiased kurtosis of a sample.

Kurtosis obtained using Fisher’s definition of kurtosis (kurtosis of normal == 0.0). Normalized by N-1.

Parameters
skipnabool, default True

Exclude NA/null values when computing the result.

Returns
scalar

Notes

Parameters currently not supported are axis, level and numeric_only

label_encoding(self, cats, dtype=None, na_sentinel=- 1)

Perform label encoding

Parameters
valuessequence of input values
dtype: numpy.dtype; optional

Specifies the output dtype. If None is given, the smallest possible integer dtype (starting with np.int8) is used.

na_sentinelnumber

Value to indicate missing category.

Returns
A sequence of encoded labels with value between 0 and n-1 classes(cats)
le(self, other, fill_value=None, axis=0)

Less than or equal to of series and other, element-wise (binary operator le).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

property loc

Select values by label.

See also

cudf.core.dataframe.Dataframe.loc
lt(self, other, fill_value=None, axis=0)

Less than of series and other, element-wise (binary operator lt).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

max(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, **kwargs)

Return the maximum of the values in the Series.

Parameters
skipnabool, default True

Exclude NA/null values when computing the result.

dtypedata type

Data type to cast the result to.

Returns
scalar

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.max()
5
mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Return the mean of the values in the series.

Parameters
skipnabool, default True

Exclude NA/null values when computing the result.

Returns
scalar

Notes

Parameters currently not supported are axis, level and numeric_only

Examples

>>> import cudf
>>> ser = cudf.Series([10, 25, 3, 25, 24, 6])
>>> ser.mean()
15.5
median(self, skipna=True)

Compute the median of the series

memory_usage(self, index=True, deep=False)

Return the memory usage of the Series.

The memory usage can optionally include the contribution of the index and of elements of object dtype.

Parameters
indexbool, default True

Specifies whether to include the memory usage of the Series index.

deepbool, default False

If True, introspect the data deeply by interrogating object dtypes for system-level memory consumption, and include it in the returned value.

Returns
int

Bytes of memory consumed.

See also

cudf.DataFrame.memory_usage

Bytes consumed by a DataFrame.

Examples

>>> s = cudf.Series(range(3), index=['a','b','c'])
>>> s.memory_usage()
48

Not including the index gives the size of the rest of the data, which is necessarily smaller:

>>> s.memory_usage(index=False)
24
min(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, **kwargs)

Return the minimum of the values in the Series.

Parameters
skipnabool, default True

Exclude NA/null values when computing the result.

dtypedata type

Data type to cast the result to.

Returns
scalar

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.min()
1
mod(self, other, fill_value=None, axis=0)

Modulo of series and other, element-wise (binary operator mod).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

mul(self, other, fill_value=None, axis=0)

Multiplication of series and other, element-wise (binary operator mul).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

property name

Returns name of the Series.

nans_to_nulls(self)

Convert nans (if any) to nulls

property ndim

Dimension of the data. Series ndim is always 1.

ne(self, other, fill_value=None, axis=0)

Not equal to of series and other, element-wise (binary operator ne).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

nlargest(self, n=5, keep='first')

Returns a new Series of the n largest element.

nsmallest(self, n=5, keep='first')

Returns a new Series of the n smallest element.

property null_count

Number of null values

property nullable

A boolean indicating whether a null-mask is needed

property nullmask

The gpu buffer for the null-mask

nunique(self, method='sort', dropna=True)

Returns the number of unique values of the Series: approximate version, and exact version to be moved to libgdf

one_hot_encoding(self, cats, dtype='float64')

Perform one-hot-encoding

Parameters
catssequence of values

values representing each category.

dtypenumpy.dtype

specifies the output dtype.

Returns
Sequence

A sequence of new series for each category. Its length is determined by the length of cats.

pow(self, other, fill_value=None, axis=0)

Exponential power of series and other, element-wise (binary operator pow).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

prod(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, min_count=0, **kwargs)

Return product of the values in the series

Parameters
skipnabool, default True

Exclude NA/null values when computing the result.

dtypedata type

Data type to cast the result to.

min_countint, default 0

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.

The default being 0. This means the sum of an all-NA or empty Series is 0, and the product of an all-NA or empty Series is 1.

Returns
scalar

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.prod()
120
product(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, min_count=0, **kwargs)

Return product of the values in the Series.

Parameters
skipnabool, default True

Exclude NA/null values when computing the result.

dtypedata type

Data type to cast the result to.

min_countint, default 0

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.

The default being 0. This means the sum of an all-NA or empty Series is 0, and the product of an all-NA or empty Series is 1.

Returns
scalar

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.product()
120
quantile(self, q=0.5, interpolation='linear', exact=True, quant_index=True)

Return values at the given quantile.

Parameters
qfloat or array-like, default 0.5 (50% quantile)

0 <= q <= 1, the quantile(s) to compute

interpolation{’linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}

This optional parameter specifies the interpolation method to use, when the desired quantile lies between two data points i and j:

columnslist of str

List of column names to include.

exactboolean

Whether to use approximate or exact quantile algorithm.

quant_indexboolean

Whether to use the list of quantiles as index.

Returns
DataFrame
radd(self, other, fill_value=None, axis=0)

Addition of series and other, element-wise (binary operator radd).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

reindex(self, index=None, copy=True)

Return a Series that conforms to a new index

Parameters
indexIndex, Series-convertible, default None
copyboolean, default True
Returns
A new Series that conforms to the supplied index
rename(self, index=None, copy=True)

Alter Series name

Change Series.name with a scalar value

Parameters
indexScalar, optional

Scalar to alter the Series.name attribute

copyboolean, default True

Also copy underlying data

Returns
Series

Notes

Difference from pandas:
  • Supports scalar values only for changing name attribute

  • Not supporting : inplace, level

replace(self, to_replace=None, value=None, inplace=False, limit=None, regex=False, method=None)

Replace values given in to_replace with value.

Parameters
to_replacenumeric, str or list-like

Value(s) to replace.

  • numeric or str:
    • values equal to to_replace will be replaced with value

  • list of numeric or str:
    • If value is also list-like, to_replace and value must be of same length.

valuenumeric, str, list-like, or dict

Value(s) to replace to_replace with.

inplacebool, default False

If True, in place.

Returns
resultSeries

Series after replacement. The mask and index are preserved.

See also

Series.fillna

Notes

Parameters that are currently not supported are: limit, regex, method

reset_index(self, drop=False, inplace=False)

Reset index to RangeIndex

reverse(self)

Reverse the Series

rfloordiv(self, other, fill_value=None, axis=0)

Integer division of series and other, element-wise (binary operator rfloordiv).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

rmod(self, other, fill_value=None, axis=0)

Modulo of series and other, element-wise (binary operator rmod).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

rmul(self, other, fill_value=None, axis=0)

Multiplication of series and other, element-wise (binary operator rmul).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

rolling(self, window, min_periods=None, center=False, axis=0, win_type=None)

Rolling window calculations.

Parameters
windowint or offset

Size of the window, i.e., the number of observations used to calculate the statistic. For datetime indexes, an offset can be provided instead of an int. The offset must be convertible to a timedelta. As opposed to a fixed window size, each window will be sized to accommodate observations within the time period specified by the offset.

min_periodsint, optional

The minimum number of observations in the window that are required to be non-null, so that the result is non-null. If not provided or None, min_periods is equal to the window size.

centerbool, optional

If True, the result is set at the center of the window. If False (default), the result is set at the right edge of the window.

Returns
Rolling object.

Examples

>>> import cudf
>>> a = cudf.Series([1, 2, 3, None, 4])

Rolling sum with window size 2.

>>> print(a.rolling(2).sum())
0
1    3
2    5
3
4
dtype: int64

Rolling sum with window size 2 and min_periods 1.

>>> print(a.rolling(2, min_periods=1).sum())
0    1
1    3
2    5
3    3
4    4
dtype: int64

Rolling count with window size 3.

>>> print(a.rolling(3).count())
0    1
1    2
2    3
3    2
4    2
dtype: int64

Rolling count with window size 3, but with the result set at the center of the window.

>>> print(a.rolling(3, center=True).count())
0    2
1    3
2    2
3    2
4    1 dtype: int64

Rolling max with variable window size specified by an offset; only valid for datetime index.

>>> a = cudf.Series(
...     [1, 9, 5, 4, np.nan, 1],
...     index=[
...         pd.Timestamp('20190101 09:00:00'),
...         pd.Timestamp('20190101 09:00:01'),
...         pd.Timestamp('20190101 09:00:02'),
...         pd.Timestamp('20190101 09:00:04'),
...         pd.Timestamp('20190101 09:00:07'),
...         pd.Timestamp('20190101 09:00:08')
...     ]
... )
>>> print(a.rolling('2s').max())
2019-01-01T09:00:00.000    1
2019-01-01T09:00:01.000    9
2019-01-01T09:00:02.000    9
2019-01-01T09:00:04.000    4
2019-01-01T09:00:07.000
2019-01-01T09:00:08.000    1
dtype: int64

Apply custom function on the window with the apply method

>>> import numpy as np
>>> import math
>>> b = cudf.Series([16, 25, 36, 49, 64, 81], dtype=np.float64)
>>> def some_func(A):
...     b = 0
...     for a in A:
...         b = b + math.sqrt(a)
...     return b
...
>>> print(b.rolling(3, min_periods=1).apply(some_func))
0     4.0
1     9.0
2    15.0
3    18.0
4    21.0
5    24.0
dtype: float64

And this also works for window rolling set by an offset

>>> import pandas as pd
>>> c = cudf.Series(
...     [16, 25, 36, 49, 64, 81],
...     index=[
...          pd.Timestamp('20190101 09:00:00'),
...          pd.Timestamp('20190101 09:00:01'),
...          pd.Timestamp('20190101 09:00:02'),
...          pd.Timestamp('20190101 09:00:04'),
...          pd.Timestamp('20190101 09:00:07'),
...          pd.Timestamp('20190101 09:00:08')
...      ],
...     dtype=np.float64
... )
>>> print(c.rolling('2s').apply(some_func))
2019-01-01T09:00:00.000     4.0
2019-01-01T09:00:01.000     9.0
2019-01-01T09:00:02.000    11.0
2019-01-01T09:00:04.000     7.0
2019-01-01T09:00:07.000     8.0
2019-01-01T09:00:08.000    17.0
dtype: float64
round(self, decimals=0)

Round a Series to a configurable number of decimal places.

rpow(self, other, fill_value=None, axis=0)

Exponential power of series and other, element-wise (binary operator rpow).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

rsub(self, other, fill_value=None, axis=0)

Subtraction of series and other, element-wise (binary operator rsub).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

rtruediv(self, other, fill_value=None, axis=0)

Floating division of series and other, element-wise (binary operator rtruediv).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

scale(self)

Scale values to [0, 1] in float64

set_index(self, index)

Returns a new Series with a different index.

Parameters
indexIndex, Series-convertible

the new index or values for the new index

set_mask(self, mask, null_count=None)

Create new Series by setting a mask array.

This will override the existing mask. The returned Series will reference the same data buffer as this Series.

Parameters
mask1D array-like

The null-mask. Valid values are marked as 1; otherwise 0. The mask bit given the data index idx is computed as:

(mask[idx // 8] >> (idx % 8)) & 1
null_countint, optional

The number of null values. If None, it is calculated automatically.

property shape

Returns a tuple representing the dimensionality of the Series.

skew(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs)

Return unbiased Fisher-Pearson skew of a sample.

Parameters
skipnabool, default True

Exclude NA/null values when computing the result.

Returns
scalar

Notes

Parameters currently not supported are axis, level and numeric_only

sort_index(self, ascending=True)

Sort by the index.

sort_values(self, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False)

Sort by the values.

Sort a Series in ascending or descending order by some criterion.

Parameters
ascendingbool, default True

If True, sort values in ascending order, otherwise descending.

na_position{‘first’, ‘last’}, default ‘last’

‘first’ puts nulls at the beginning, ‘last’ puts nulls at the end.

ignore_indexbool, default False

If True, index will not be sorted.

Returns
sorted_objcuDF Series

Notes

Difference from pandas:
  • Not supporting: inplace, kind

Examples

>>> import cudf
>>> s = cudf.Series([1, 5, 2, 4, 3])
>>> s.sort_values()
0    1
2    2
4    3
3    4
1    5
std(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs)

Return sample standard deviation of the Series.

Normalized by N-1 by default. This can be changed using the ddof argument

Parameters
skipnabool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

ddofint, default 1

Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements.

Returns
scalar

Notes

Parameters currently not supported are axis, level and numeric_only

property str

Vectorized string functions for Series and Index.

This mimics pandas df.str interface. nulls stay null unless handled otherwise by a particular method. Patterned after Python’s string methods, with some inspiration from R’s stringr package.

sub(self, other, fill_value=None, axis=0)

Subtraction of series and other, element-wise (binary operator sub).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

sum(self, axis=None, skipna=None, dtype=None, level=None, numeric_only=None, min_count=0, **kwargs)

Return sum of the values in the Series.

Parameters
skipnabool, default True

Exclude NA/null values when computing the result.

dtypedata type

Data type to cast the result to.

min_countint, default 0

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.

The default being 0. This means the sum of an all-NA or empty Series is 0, and the product of an all-NA or empty Series is 1.

Returns
scalar

Notes

Parameters currently not supported are axis, level, numeric_only.

Examples

>>> import cudf
>>> ser = cudf.Series([1, 5, 2, 4, 3])
>>> ser.sum()
15
tail(self, n=5)

Returns the last n rows as a new Series

Examples

>>> import cudf
>>> ser = cudf.Series([4, 3, 2, 1, 0])
>>> print(ser.tail(2))
3    1
4    0
take(self, indices, keep_index=True)

Return Series by taking values from the corresponding indices.

to_array(self, fillna=None)

Get a dense numpy array for the data.

Parameters
fillnastr or None

Defaults to None, which will skip null values. If it equals “pandas”, null values are filled with NaNs. Non integral dtype is promoted to np.float64.

Notes

If fillna is None, null values are skipped. Therefore, the output size could be smaller.

to_arrow(self)

Convert Series to a PyArrow Array.

Examples

>>> import cudf
>>> ser = cudf.Series([-3, 10, 15, 20])
>>> ser.to_arrow()
<pyarrow.lib.Int64Array object at 0x7f5e769499f0>
[
-3,
10,
15,
20
]
to_dlpack(self)

Converts a cuDF object into a DLPack tensor.

DLPack is an open-source memory tensor structure: dmlc/dlpack.

This function takes a cuDF object and converts it to a PyCapsule object which contains a pointer to a DLPack tensor. This function deep copies the data into the DLPack tensor from the cuDF object.

Parameters
cudf_objDataFrame, Series, Index, or Column
Returns
pycapsule_objPyCapsule

Output DLPack tensor pointer which is encapsulated in a PyCapsule object.

to_frame(self, name=None)

Convert Series into a DataFrame

Parameters
namestr, default None

Name to be used for the column

Returns
DataFrame

cudf DataFrame

to_gpu_array(self, fillna=None)

Get a dense numba device array for the data.

Parameters
fillnastr or None

See fillna in .to_array.

Notes

if fillna is None, null values are skipped. Therefore, the output size could be smaller.

to_hdf(self, path_or_buf, key, *args, **kwargs)

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.

For more information see the user guide.

Parameters
path_or_bufstr or pandas.HDFStore

File path or HDFStore object.

keystr

Identifier for the group in the store.

mode{‘a’, ‘w’, ‘r+’}, default ‘a’

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.

format{‘fixed’, ‘table’}, default ‘fixed’

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.

appendbool, default False

For Table formats, append the input data to the existing.

data_columnslist of columns or True, optional

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’.

complevel{0-9}, optional

Specifies a compression level for data. A value of 0 disables compression.

complib{‘zlib’, ‘lzo’, ‘bzip2’, ‘blosc’}, default ‘zlib’

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.

fletcher32bool, default False

If applying compression use the fletcher32 checksum.

dropnabool, default False

If true, ALL nan rows will not be written to store.

errorsstr, default ‘strict’

Specifies how encoding and decoding errors are to be handled. See the errors argument for open() for a full list of options.

See also

cudf.io.hdf.read_hdf

Read from HDF file.

cudf.io.parquet.to_parquet

Write a DataFrame to the binary parquet format.

cudf.io.feather.to_feather

Write out feather-format for DataFrames.

to_json(self, path_or_buf=None, *args, **kwargs)

Convert the cuDF object to a JSON string. Note nulls and NaNs will be converted to null and datetime objects will be converted to UNIX timestamps.

Parameters
path_or_bufstring or file handle, optional

File path or object. If not specified, the result is returned as a string.

orientstring

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, and the data component is like orient='records'.

date_format{None, ‘epoch’, ‘iso’}

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’.

double_precisionint, default 10

The number of decimal places to use when encoding floating point values.

force_asciibool, default True

Force encoded string to be ASCII.

date_unitstring, default ‘ms’ (milliseconds)

The time unit to encode to, governs timestamp and ISO8601 precision. One of ‘s’, ‘ms’, ‘us’, ‘ns’ for second, millisecond, microsecond, and nanosecond respectively.

default_handlercallable, default None

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 serializable object.

linesbool, default False

If ‘orient’ is ‘records’ write out line delimited json format. Will throw ValueError if incorrect ‘orient’ since others are not list like.

compression{‘infer’, ‘gzip’, ‘bz2’, ‘zip’, ‘xz’, None}

A string representing the compression to use in the output file, only used when the first argument is a filename. By default, the compression is inferred from the filename.

indexbool, default True

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’.

to_pandas(self, index=True)

Convert to a Pandas Series.

Parameters
indexBoolean, Default True

If index is True, converts the index of cudf.Series and sets it to the pandas.Series. If index is False, no index conversion is performed and pandas.Series will assign a default index.

Examples

>>> import cudf
>>> ser = cudf.Series([-3, 2, 0])
>>> pds = ser.to_pandas()
>>> pds
0   -3
1    2
2    0
dtype: int64
>>> type(pds)
<class 'pandas.core.series.Series'>
to_string(self)

Convert to string

Uses Pandas formatting internals to produce output identical to Pandas. Use the Pandas formatting settings directly in Pandas to control cuDF output.

tolist(self)

Return a list type from series data.

Returns
list
truediv(self, other, fill_value=None, axis=0)

Floating division of series and other, element-wise (binary operator truediv).

Parameters
otherSeries or scalar value
fill_valueNone or value

Value to fill nulls with before computation. If data in both corresponding Series locations is null the result will be null

unique(self)

Returns unique values of this Series.

property valid_count

Number of non-null values

value_counts(self, normalize=False, sort=True, ascending=False, bins=None, dropna=True)

Return a Series containing counts of unique values.

The resulting object will be in descending order so that the first element is the most frequently-occurring element. Excludes NA values by default.

Parameters
normalizebool, default False

If True then the object returned will contain the relative frequencies of the unique values. normalize == True is not supported.

sortbool, default True

Sort by frequencies.

ascendingbool, default False

Sort in ascending order.

binsint, optional

Rather than count values, group them into half-open bins, works with numeric data. Not yet supported.

dropnabool, default True

Don’t include counts of NaN and None. dropna == False is not supported

Returns
resultSeries contanining counts of unique values.

Examples

>>> import cudf
>>> sr = cudf.Series([1.0, 2.0, 2.0, 3.0, 3.0, 3.0, None])
>>> sr.value_counts(ascending=True)
1.0    1
2.0    2
3.0    3
dtype: int32
property values

Return a CuPy representation of the Series.

Only the values in the Series will be returned.

Returns
outcupy.ndarray

The values of the Series.

Examples

>>> import cudf
>>> ser = cudf.Series([1, -10, 100, 20])
>>> ser.values
array([  1, -10, 100,  20])
>>> type(ser.values)
<class 'cupy.core.core.ndarray'>
property values_host

Return a numpy representation of the Series.

Only the values in the Series will be returned.

Returns
outnumpy.ndarray

The values of the Series.

Examples

>>> import cudf
>>> ser = cudf.Series([1, -10, 100, 20])
>>> ser.values_host
array([  1, -10, 100,  20])
>>> type(ser.values)
<class 'numpy.ndarray'>
values_to_string(self, nrows=None)

Returns a list of string for each element.

var(self, axis=None, skipna=None, level=None, ddof=1, numeric_only=None, **kwargs)

Return unbiased variance of the Series.

Normalized by N-1 by default. This can be changed using the ddof argument

Parameters
skipnabool, default True

Exclude NA/null values. If an entire row/column is NA, the result will be NA.

ddofint, default 1

Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements.

Returns
scalar

Notes

Parameters currently not supported are axis, level and numeric_only

Strings

class cudf.core.column.string.StringMethods(column, parent=None)

Vectorized string functions for Series and Index.

This mimics pandas df.str interface. nulls stay null unless handled otherwise by a particular method. Patterned after Python’s string methods, with some inspiration from R’s stringr package.

Methods

byte_count(self, **kwargs)

Computes the number of bytes of each string in the Series/Index.

capitalize(self, **kwargs)

Convert strings in the Series/Index to be capitalized.

cat(self[, others, sep, na_rep])

Concatenate strings in the Series/Index with given separator.

center(self, width[, fillchar])

Filling left and right side of strings in the Series/Index with an additional character.

character_ngrams(self[, n])

Generate the n-grams from characters in a column of strings.

character_tokenize(self, **kwargs)

Each string is split into individual characters.

code_points(self, **kwargs)

Returns an array by filling it with the UTF-8 code point values for each character of each string.

contains(self, pat[, case, flags, na, regex])

Test if pattern or regex is contained within a string of a Series or Index.

count(self, pat[, flags])

Count occurrences of pattern in each string of the Series/Index.

endswith(self, pat, **kwargs)

Test if the end of each string element matches a pattern.

extract(self, pat[, flags, expand])

Extract capture groups in the regex pat as columns in a DataFrame.

find(self, sub[, start, end])

Return lowest indexes in each strings in the Series/Index where the substring is fully contained between [start:end].

findall(self, pat[, flags])

Find all occurrences of pattern or regular expression in the Series/Index.

get(self[, i])

Extract element from each component at specified position.

htoi(self)

Returns integer value represented by each hex string.

index(self, sub[, start, end])

Return lowest indexes in each strings where the substring is fully contained between [start:end].

insert(self[, start, repl])

Insert the specified string into each string in the specified position.

ip2int(self)

This converts ip strings to integers

isalnum(self, **kwargs)

Check whether all characters in each string are alphanumeric.

isalpha(self, **kwargs)

Check whether all characters in each string are alphabetic.

isdecimal(self, **kwargs)

Check whether all characters in each string are decimal.

isdigit(self, **kwargs)

Check whether all characters in each string are digits.

isempty(self, **kwargs)

Check whether each string is an empty string.

isfloat(self, **kwargs)

Check whether all characters in each string form floating value.

ishex(self, **kwargs)

Check whether all characters in each string form a hex integer.

isinteger(self, **kwargs)

Check whether all characters in each string form integer.

islower(self, **kwargs)

Check whether all characters in each string are lowercase.

isnumeric(self, **kwargs)

Check whether all characters in each string are numeric.

isspace(self, **kwargs)

Check whether all characters in each string are whitespace.

isupper(self, **kwargs)

Check whether all characters in each string are uppercase.

join(self, sep)

Join lists contained as elements in the Series/Index with passed delimiter.

len(self, **kwargs)

Computes the length of each element in the Series/Index.

ljust(self, width[, fillchar])

Filling right side of strings in the Series/Index with an additional character.

lower(self, **kwargs)

Converts all characters to lowercase.

lstrip(self[, to_strip])

Remove leading and trailing characters.

match(self, pat[, case, flags])

Determine if each string matches a regular expression.

ngrams(self[, n, separator])

Generate the n-grams from a set of tokens, each record in series is treated a token.

ngrams_tokenize(self[, n, delimiter, separator])

Generate the n-grams using tokens from each string.

normalize_spaces(self, **kwargs)

Remove extra whitespace between tokens and trim whitespace from the beginning and the end of each string.

pad(self, width[, side, fillchar])

Pad strings in the Series/Index up to width.

partition(self[, sep, expand])

Split the string at the first occurrence of sep.

replace(self, pat, repl[, n, case, flags, regex])

Replace occurrences of pattern/regex in the Series/Index with some other string.

replace_tokens(self, targets, replacements)

The targets tokens are searched for within each string in the series and replaced with the corresponding replacements if found.

replace_with_backrefs(self, pat, repl, **kwargs)

Use the repl back-ref template to create a new string with the extracted elements found using the pat expression.

rfind(self, sub[, start, end])

Return highest indexes in each strings in the Series/Index where the substring is fully contained between [start:end].

rindex(self, sub[, start, end])

Return highest indexes in each strings where the substring is fully contained between [start:end].

rjust(self, width[, fillchar])

Filling left side of strings in the Series/Index with an additional character.

rpartition(self[, sep, expand])

Split the string at the last occurrence of sep.

rsplit(self[, pat, n, expand])

Split strings around given separator/delimiter.

rstrip(self[, to_strip])

Remove leading and trailing characters.

slice(self[, start, stop, step])

Slice substrings from each element in the Series or Index.

slice_from(self, starts, stops, **kwargs)

Return substring of each string using positions for each string.

slice_replace(self[, start, stop, repl])

Replace the specified section of each string with a new string.

split(self[, pat, n, expand])

Split strings around given separator/delimiter.

startswith(self, pat, **kwargs)

Test if the start of each string element matches a pattern.

strip(self[, to_strip])

Remove leading and trailing characters.

swapcase(self, **kwargs)

Change each lowercase character to uppercase and vice versa.

title(self, **kwargs)

Uppercase the first letter of each letter after a space and lowercase the rest.

token_count(self[, delimiter])

Each string is split into tokens using the provided delimiter.

tokenize(self[, delimiter])

Each string is split into tokens using the provided delimiter(s).

translate(self, table, **kwargs)

Map all characters in the string through the given mapping table.

upper(self, **kwargs)

Convert each string to uppercase.

url_decode(self, **kwargs)

Returns a URL-decoded format of each string.

url_encode(self, **kwargs)

Returns a URL-encoded format of each string.

wrap(self, width, **kwargs)

Wrap long strings in the Series/Index to be formatted in paragraphs with length less than a given width.

zfill(self, width, **kwargs)

Pad strings in the Series/Index by prepending ‘0’ characters.

byte_count(self, **kwargs)

Computes the number of bytes of each string in the Series/Index.

ReturnsSeries or Index of int

A Series or Index of integer values indicating the number of bytes of each strings in the Series or Index.

Examples

>>> import cudf
>>> s = cudf.Series(["abc","d","ef"])
>>> s.str.byte_count()
0    3
1    1
2    2
dtype: int32
>>> s = cudf.Series(["Hello", "Bye", "Thanks 😊"])
>>> s.str.byte_count()
0     5
1     3
2    11
dtype: int32
capitalize(self, **kwargs)

Convert strings in the Series/Index to be capitalized. This only applies to ASCII characters at this time.

Returns
Series or Index of object

Examples

>>> import cudf
>>> data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
>>> s = cudf.Series(data)
>>> s.str.capitalize()
0                 Lower
1              Capitals
2    This is a sentence
3              Swapcase
dtype: object
>>> s = cudf.Series(["hello, friend","goodbye, friend"])
>>> s.str.capitalize()
0      Hello, friend
1    Goodbye, friend
dtype: object
cat(self, others=None, sep=None, na_rep=None, **kwargs)

Concatenate strings in the Series/Index with given separator.

If others is specified, this function concatenates the Series/Index and elements of others element-wise. If others is not passed, then all values in the Series/Index are concatenated into a single string with a given sep.

Parameters
othersSeries or List of str

Strings to be appended. The number of strings must match size() of this instance. This must be either a Series of string dtype or a Python list of strings.

sepstr

If specified, this separator will be appended to each string before appending the others.

na_repstr

This character will take the place of any null strings (not empty strings) in either list.

  • If na_rep is None, and others is None, missing values in the Series/Index are omitted from the result.

  • If na_rep is None, and others is not None, a row containing a missing value in any of the columns (before concatenation) will have a missing value in the result.

Returns
concatstr or Series/Index of str dtype

If others is None, str is returned, otherwise a Series/Index (same type as caller) of str dtype is returned.

Examples

>>> import cudf
>>> s = cudf.Series(['a', 'b', None, 'd'])
>>> s.str.cat(sep=' ')
'a b d'

By default, NA values in the Series are ignored. Using na_rep, they can be given a representation:

>>> s.str.cat(sep=' ', na_rep='?')
'a b ? d'

If others is specified, corresponding values are concatenated with the separator. Result will be a Series of strings.

>>> s.str.cat(['A', 'B', 'C', 'D'], sep=',')
0     a,A
1     b,B
2    None
3     d,D
dtype: object

Missing values will remain missing in the result, but can again be represented using na_rep

>>> s.str.cat(['A', 'B', 'C', 'D'], sep=',', na_rep='-')
0    a,A
1    b,B
2    -,C
3    d,D
dtype: object

If sep is not specified, the values are concatenated without separation.

>>> s.str.cat(['A', 'B', 'C', 'D'], na_rep='-')
0    aA
1    bB
2    -C
3    dD
dtype: object
center(self, width, fillchar=' ', **kwargs)

Filling left and right side of strings in the Series/Index with an additional character.

Parameters
widthint

Minimum width of resulting string; additional characters will be filled with fillchar.

fillcharstr, default is ‘ ‘ (whitespace)

Additional character for filling.

Returns
Series/Index of str dtype

Returns Series or Index.

Examples

>>> import cudf
>>> s = cudf.Series(['a', 'b', None, 'd'])
>>> s.str.center(1)
0       a
1       b
2    None
3       d
dtype: object
>>> s.str.center(1, fillchar='-')
0       a
1       b
2    None
3       d
dtype: object
>>> s.str.center(2, fillchar='-')
0      a-
1      b-
2    None
3      d-
dtype: object
>>> s.str.center(5, fillchar='-')
0    --a--
1    --b--
2     None
3    --d--
dtype: object
>>> s.str.center(6, fillchar='-')
0    --a---
1    --b---
2      None
3    --d---
dtype: object
character_ngrams(self, n=2, **kwargs)

Generate the n-grams from characters in a column of strings.

Parameters
nint

The degree of the n-gram (number of consecutive characters). Default of 2 for bigrams.

Examples

>>> import cudf
>>> str_series = cudf.Series(['abcd','efgh','xyz'])
>>> str_series.str.character_ngrams(2)
0    ab
1    bc
2    cd
3    ef
4    fg
5    gh
6    xy
7    yz
dtype: object
>>> str_series.str.character_ngrams(3)
0    abc
1    bcd
2    efg
3    fgh
4    xyz
dtype: object
character_tokenize(self, **kwargs)

Each string is split into individual characters. The sequence returned contains each character as an individual string.

Returns
Series or Index of object.

Examples

>>> import cudf
>>> data = ["hello world", None, "goodbye, thank you."]
>>> ser = cudf.Series(data)
>>> ser.str.character_tokenize()
0     h
1     e
2     l
3     l
4     o
5
6     w
7     o
8     r
9     l
10    d
11    g
12    o
13    o
14    d
15    b
16    y
17    e
18    ,
19
20    t
21    h
22    a
23    n
24    k
25
26    y
27    o
28    u
29    .
dtype: object
code_points(self, **kwargs)

Returns an array by filling it with the UTF-8 code point values for each character of each string. This function uses the len() method to determine the size of each sub-array of integers.

Returns
Series or Index.

Examples

>>> import cudf
>>> s = cudf.Series(["a","xyz", "éee"])
>>> s.str.code_points()
0       97
1      120
2      121
3      122
4    50089
5      101
6      101
dtype: int32
>>> s = cudf.Series(["abc"])
>>> s.str.code_points()
0    97
1    98
2    99
dtype: int32
contains(self, pat, case=True, flags=0, na=nan, regex=True, **kwargs)

Test if pattern or regex is contained within a string of a Series or Index.

Return boolean Series or Index based on whether a given pattern or regex is contained within a string of a Series or Index.

Parameters
patstr

Character sequence or regular expression.

regexbool, default True

If True, assumes the pattern is a regular expression. If False, treats the pattern as a literal string.

Returns
Series/Index of bool dtype

A Series/Index of boolean dtype indicating whether the given pattern is contained within the string of each element of the Series/Index.

Notes

The parameters case, flags, and na are not yet supported and will raise a NotImplementedError if anything other than the default value is set.

Examples

>>> import cudf
>>> s1 = cudf.Series(['Mouse', 'dog', 'house and parrot', '23', None])
>>> s1
0               Mouse
1                 dog
2    house and parrot
3                  23
4                None
dtype: object
>>> s1.str.contains('og', regex=False)
0    False
1     True
2    False
3    False
4     null
dtype: bool

Returning an Index of booleans using only a literal pattern.

>>> data = ['Mouse', 'dog', 'house and parrot', '23.0', np.NaN]
>>> ind = cudf.core.index.StringIndex(data)
>>> ind.str.contains('23', regex=False)
Index(['False', 'False', 'False', 'True', 'null'], dtype='object')

Returning ‘house’ or ‘dog’ when either expression occurs in a string.

>>> s1.str.contains('house|dog', regex=True)
0    False
1     True
2     True
3    False
4     null
dtype: bool

Returning any digit using regular expression.

>>> s1.str.contains('\d', regex=True)                               # noqa W605
0    False
1    False
2    False
3     True
4     null
dtype: bool

Ensure pat is a not a literal pattern when regex is set to True. Note in the following example one might expect only s2[1] and s2[3] to return True. However, ‘.0’ as a regex matches any character followed by a 0.

>>> s2 = cudf.Series(['40', '40.0', '41', '41.0', '35'])
>>> s2.str.contains('.0', regex=True)
0     True
1     True
2    False
3     True
4    False
dtype: bool
count(self, pat, flags=0, **kwargs)

Count occurrences of pattern in each string of the Series/Index.

This function is used to count the number of times a particular regex pattern is repeated in each of the string elements of the Series.

Parameters
patstr

Valid regular expression.

Returns
Series or Index

Notes

  • flags parameter is currently not supported.

  • Some characters need to be escaped when passing in pat. eg. '$' has a special meaning in regex and must be escaped when finding this literal character.

Examples

>>> import cudf
>>> s = cudf.Series(['A', 'B', 'Aaba', 'Baca', None, 'CABA', 'cat'])
>>> s.str.count('a')
0       0
1       0
2       2
3       2
4    null
5       0
6       1
dtype: int32

Escape '$' to find the literal dollar sign.

>>> s = cudf.Series(['$', 'B', 'Aab$', '$$ca', 'C$B$', 'cat'])
>>> s.str.count('\$')                                       # noqa W605
0    1
1    0
2    1
3    2
4    2
5    0
dtype: int32

This is also available on Index.

>>> index = cudf.core.index.StringIndex(['A', 'A', 'Aaba', 'cat'])
>>> index.str.count('a')
Int64Index([0, 0, 2, 1], dtype='int64')
endswith(self, pat, **kwargs)

Test if the end of each string element matches a pattern.

Parameters
patstr or list-like

If str is an str, evaluates whether each string of series ends with pat. If pat is a list-like, evaluates whether self[i] ends with pat[i]. Regular expressions are not accepted.

Returns
Series or Index of bool

A Series of booleans indicating whether the given pattern matches the end of each string element.

Notes

na parameter is not yet supported, as cudf uses native strings instead of Python objects.

Examples

>>> import cudf
>>> s = cudf.Series(['bat', 'bear', 'caT', None])
>>> s
0     bat
1    bear
2     caT
3    None
dtype: object
>>> s.str.endswith('t')
0     True
1    False
2    False
3     null
dtype: bool
extract(self, pat, flags=0, expand=True, **kwargs)

Extract capture groups in the regex pat as columns in a DataFrame.

For each subject string in the Series, extract groups from the first match of regular expression pat.

Parameters
patstr

Regular expression pattern with capturing groups.

expandbool, default True

If True, return DataFrame with on column per capture group. If False, return a Series/Index if there is one capture group or DataFrame if there are multiple capture groups.

Returns
DataFrame or Series/Index

A DataFrame with one row for each subject string, and one column for each group. If expand=False and pat has only one capture group, then return a Series/Index.

Notes

The flags parameter is not yet supported and will raise a NotImplementedError if anything other than the default value is passed.

Examples

>>> import cudf
>>> s = cudf.Series(['a1', 'b2', 'c3'])
>>> s.str.extract(r'([ab])(\d)')                                # noqa W605
      0     1
0     a     1
1     b     2
2  None  None

A pattern with one group will return a DataFrame with one column if expand=True.

>>> s.str.extract(r'[ab](\d)', expand=True)                     # noqa W605
      0
0     1
1     2
2  None

A pattern with one group will return a Series if expand=False.

>>> s.str.extract(r'[ab](\d)', expand=False)                    # noqa W605
0       1
1       2
2    None
dtype: object
find(self, sub, start=0, end=None, **kwargs)

Return lowest indexes in each strings in the Series/Index where the substring is fully contained between [start:end]. Return -1 on failure.

Parameters
substr

Substring being searched.

startint

Left edge index.

endint

Right edge index.

Returns
Series or Index of int

Examples

>>> import cudf
>>> s = cudf.Series(['abc', 'a','b' ,'ddb'])
>>> s.str.find('b')
0    1
1   -1
2    0
3    2
dtype: int32

Parameters such as start and end can also be used.

>>> s.str.find('b', start=1, end=5)
0    1
1   -1
2   -1
3    2
dtype: int32
findall(self, pat, flags=0, **kwargs)

Find all occurrences of pattern or regular expression in the Series/Index.

Parameters
patstr

Pattern or regular expression.

Returns
DataFrame

All non-overlapping matches of pattern or regular expression in each string of this Series/Index.

Notes

flags parameter is currently not supported.

Examples

>>> import cudf
>>> s = cudf.Series(['Lion', 'Monkey', 'Rabbit'])

The search for the pattern ‘Monkey’ returns one match:

>>> s.str.findall('Monkey')
        0
0    None
1  Monkey
2    None

When the pattern matches more than one string in the Series, all matches are returned:

>>> s.str.findall('on')
      0
0    on
1    on
2  None

Regular expressions are supported too. For instance, the search for all the strings ending with the word ‘on’ is shown next:

>>> s.str.findall('on$')
      0
0    on
1  None
2  None

If the pattern is found more than once in the same string, then multiple strings are returned as columns:

>>> s.str.findall('b')
      0     1
0  None  None
1  None  None
2     b     b
get(self, i=0, **kwargs)

Extract element from each component at specified position.

Parameters
iint

Position of element to extract.

Returns
Series/Index of str dtype

Examples

>>> import cudf
>>> s = cudf.Series(["hello world", "rapids", "cudf"])
>>> s
0    hello world
1         rapids
2           cudf
dtype: object
>>> s.str.get(10)
0    d
1
2
dtype: object
>>> s.str.get(1)
0    e
1    a
2    u
dtype: object

get also accepts negative index number.

>>> s.str.get(-1)
0    d
1    s
2    f
dtype: object
htoi(self)

Returns integer value represented by each hex string. String is interpretted to have hex (base-16) characters.

Returns
Series/Index of str dtype

Examples

>>> import cudf
>>> s = cudf.Series(["1234", "ABCDEF", "1A2", "cafe"])
>>> s.str.htoi()
0        4660
1    11259375
2         418
3       51966
dtype: int64
index(self, sub, start=0, end=None, **kwargs)

Return lowest indexes in each strings where the substring is fully contained between [start:end]. This is the same as str.find except instead of returning -1, it raises a ValueError when the substring is not found.

Parameters
substr

Substring being searched.

startint

Left edge index.

endint

Right edge index.

Returns
Series or Index of object

Examples

>>> import cudf
>>> s = cudf.Series(['abc', 'a','b' ,'ddb'])
>>> s.str.index('b')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found

Parameters such as start and end can also be used.

>>> s = cudf.Series(['abc', 'abb','ab' ,'ddb'])
>>> s.str.index('b', start=1, end=5)
0    1
1    1
2    1
3    2
dtype: int32
insert(self, start=0, repl=None, **kwargs)

Insert the specified string into each string in the specified position.

Parameters
startint

Beginning position of the string to replace. Default is beginning of the each string. Specify -1 to insert at the end of each string.

replstr

String to insert into the specified position value.

Returns
Series/Index of str dtype

A new string series with the specified string inserted at the specified position.

Examples

>>> import cudf
>>> s = cudf.Series(["abcdefghij", "0123456789"])
>>> s.str.insert(2, '_')
0    ab_cdefghij
1    01_23456789
dtype: object

When no repl is passed, nothing is inserted.

>>> s.str.insert(2)
0    abcdefghij
1    0123456789
dtype: object

Negative values are also supported for start.

>>> s.str.insert(-1,'_')
0    abcdefghij_
1    0123456789_
dtype: object
ip2int(self)

This converts ip strings to integers

Returns
Series/Index of str dtype

Examples

>>> import cudf
>>> s = cudf.Series(["12.168.1.1", "10.0.0.1"])
>>> s.str.ip2int()
0    212336897
1    167772161
dtype: int64

Returns 0’s if any string is not an IP.

>>> s = cudf.Series(["12.168.1.1", "10.0.0.1", "abc"])
>>> s.str.ip2int()
0    212336897
1    167772161
2            0
dtype: int64
isalnum(self, **kwargs)

Check whether all characters in each string are alphanumeric.

This is equivalent to running the Python string method str.isalnum() for each element of the Series/Index. If a string has zero characters, False is returned for that check.

Equivalent to: isalpha() or isdigit() or isnumeric() or isdecimal()

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isalpha

Check whether all characters are alphabetic.

isdecimal

Check whether all characters are decimal.

isdigit

Check whether all characters are digits.

isinteger

Check whether all characters are integer.

isnumeric

Check whether all characters are numeric.

isfloat

Check whether all characters are float.

islower

Check whether all characters are lowercase.

isspace

Check whether all characters are whitespace.

isupper

Check whether all characters are uppercase.

Examples

>>> import cudf
>>> s1 = cudf.Series(['one', 'one1', '1', ''])
>>> s1.str.isalnum()
0     True
1     True
2     True
3    False
dtype: bool

Note that checks against characters mixed with any additional punctuation or whitespace will evaluate to false for an alphanumeric check.

>>> s2 = cudf.Series(['A B', '1.5', '3,000'])
>>> s2.str.isalnum()
0    False
1    False
2    False
dtype: bool
isalpha(self, **kwargs)

Check whether all characters in each string are alphabetic.

This is equivalent to running the Python string method str.isalpha() for each element of the Series/Index. If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isalnum

Check whether all characters are alphanumeric.

isdecimal

Check whether all characters are decimal.

isdigit

Check whether all characters are digits.

isinteger

Check whether all characters are integer.

isnumeric

Check whether all characters are numeric.

isfloat

Check whether all characters are float.

islower

Check whether all characters are lowercase.

isspace

Check whether all characters are whitespace.

isupper

Check whether all characters are uppercase.

Examples

>>> import cudf
>>> s1 = cudf.Series(['one', 'one1', '1', ''])
>>> s1.str.isalpha()
0     True
1    False
2    False
3    False
dtype: bool
isdecimal(self, **kwargs)

Check whether all characters in each string are decimal.

This is equivalent to running the Python string method str.isdecimal() for each element of the Series/Index. If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isalnum

Check whether all characters are alphanumeric.

isalpha

Check whether all characters are alphabetic.

isdigit

Check whether all characters are digits.

isinteger

Check whether all characters are integer.

isnumeric

Check whether all characters are numeric.

isfloat

Check whether all characters are float.

islower

Check whether all characters are lowercase.

isspace

Check whether all characters are whitespace.

isupper

Check whether all characters are uppercase.

Examples

>>> import cudf
>>> s3 = cudf.Series(['23', '³', '⅕', ''])

The s3.str.isdecimal method checks for characters used to form numbers in base 10.

>>> s3.str.isdecimal()
0     True
1    False
2    False
3    False
dtype: bool
isdigit(self, **kwargs)

Check whether all characters in each string are digits.

This is equivalent to running the Python string method str.isdigit() for each element of the Series/Index. If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isalnum

Check whether all characters are alphanumeric.

isalpha

Check whether all characters are alphabetic.

isdecimal

Check whether all characters are decimal.

isinteger

Check whether all characters are integer.

isnumeric

Check whether all characters are numeric.

isfloat

Check whether all characters are float.

islower

Check whether all characters are lowercase.

isspace

Check whether all characters are whitespace.

isupper

Check whether all characters are uppercase.

Examples

>>> import cudf
>>> s = cudf.Series(['23', '³', '⅕', ''])

The s.str.isdigit method is the same as s.str.isdecimal but also includes special digits, like superscripted and subscripted digits in unicode.

>>> s.str.isdigit()
0     True
1     True
2    False
3    False
dtype: bool
isempty(self, **kwargs)

Check whether each string is an empty string.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

Examples

>>> import cudf
>>> s = cudf.Series(["1", "abc", "", " ", None])
>>> s.str.isempty()
0    False
1    False
2     True
3    False
4    False
dtype: bool
isfloat(self, **kwargs)

Check whether all characters in each string form floating value.

If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

“, “9.9”, “9.9.9”])
>>> s.str.isfloat()
0    False
1    False
2     True
3    False
dtype: bool
ishex(self, **kwargs)

Check whether all characters in each string form a hex integer.

If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isdecimal

Check whether all characters are decimal.

isdigit

Check whether all characters are digits.

isnumeric

Check whether all characters are numeric.

isfloat

Check whether all characters are float.

Examples

>>> import cudf
>>> s = cudf.Series(["", "123DEF", "0x2D3", "-15", "abc"])
>>> s.str.ishex()
0    False
1     True
2     True
3    False
4     True
dtype: bool
isinteger(self, **kwargs)

Check whether all characters in each string form integer.

If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isalnum

Check whether all characters are alphanumeric.

isalpha

Check whether all characters are alphabetic.

isdecimal

Check whether all characters are decimal.

isdigit

Check whether all characters are digits.

isnumeric

Check whether all characters are numeric.

isfloat

Check whether all characters are float.

islower

Check whether all characters are lowercase.

isspace

Check whether all characters are whitespace.

isupper

Check whether all characters are uppercase.

Examples

>>> import cudf
>>> s = cudf.Series(["1", "0.1", "+100", "-15", "abc"])
>>> s.str.isinteger()
0     True
1    False
2     True
3     True
4    False
dtype: bool
>>> s = cudf.Series(["this is plan text", "", "10 10"])
>>> s.str.isinteger()
0    False
1    False
2    False
dtype: bool
islower(self, **kwargs)

Check whether all characters in each string are lowercase.

This is equivalent to running the Python string method str.islower() for each element of the Series/Index. If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isalnum

Check whether all characters are alphanumeric.

isalpha

Check whether all characters are alphabetic.

isdecimal

Check whether all characters are decimal.

isdigit

Check whether all characters are digits.

isinteger

Check whether all characters are integer.

isnumeric

Check whether all characters are numeric.

isfloat

Check whether all characters are float.

isspace

Check whether all characters are whitespace.

isupper

Check whether all characters are uppercase.

Examples

>>> import cudf
>>> s = cudf.Series(['leopard', 'Golden Eagle', 'SNAKE', ''])
>>> s.str.islower()
0     True
1    False
2    False
3    False
dtype: bool
isnumeric(self, **kwargs)

Check whether all characters in each string are numeric.

This is equivalent to running the Python string method str.isnumeric() for each element of the Series/Index. If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isalnum

Check whether all characters are alphanumeric.

isalpha

Check whether all characters are alphabetic.

isdecimal

Check whether all characters are decimal.

isdigit

Check whether all characters are digits.

isinteger

Check whether all characters are integer.

isfloat

Check whether all characters are float.

islower

Check whether all characters are lowercase.

isspace

Check whether all characters are whitespace.

isupper

Check whether all characters are uppercase.

Examples

>>> import cudf
>>> s1 = cudf.Series(['one', 'one1', '1', ''])
>>> s1.str.isnumeric()
0    False
1    False
2     True
3    False
dtype: bool

The s1.str.isnumeric method is the same as s2.str.isdigit but also includes other characters that can represent quantities such as unicode fractions.

>>> s2 = pd.Series(['23', '³', '⅕', ''])
>>> s2.str.isnumeric()
0     True
1     True
2     True
3    False
dtype: bool
isspace(self, **kwargs)

Check whether all characters in each string are whitespace.

This is equivalent to running the Python string method str.isspace() for each element of the Series/Index. If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isalnum

Check whether all characters are alphanumeric.

isalpha

Check whether all characters are alphabetic.

isdecimal

Check whether all characters are decimal.

isdigit

Check whether all characters are digits.

isinteger

Check whether all characters are integer.

isnumeric

Check whether all characters are numeric.

isfloat

Check whether all characters are float.

islower

Check whether all characters are lowercase.

isupper

Check whether all characters are uppercase.

Examples

>>> import cudf
>>> s = cudf.Series([' ', '\t\r\n ', ''])
>>> s.str.isspace()
0     True
1     True
2    False
dtype: bool
isupper(self, **kwargs)

Check whether all characters in each string are uppercase.

This is equivalent to running the Python string method str.isupper() for each element of the Series/Index. If a string has zero characters, False is returned for that check.

ReturnsSeries or Index of bool

Series or Index of boolean values with the same length as the original Series/Index.

See also

isalnum

Check whether all characters are alphanumeric.

isalpha

Check whether all characters are alphabetic.

isdecimal

Check whether all characters are decimal.

isdigit

Check whether all characters are digits.

isinteger

Check whether all characters are integer.

isnumeric

Check whether all characters are numeric.

isfloat

Check whether all characters are float.

islower

Check whether all characters are lowercase.

isspace

Check whether all characters are whitespace.

Examples

>>> import cudf
>>> s = cudf.Series(['leopard', 'Golden Eagle', 'SNAKE', ''])
>>> s.str.isupper()
0    False
1    False
2     True
3    False
dtype: bool
join(self, sep)

Join lists contained as elements in the Series/Index with passed delimiter.

RaisesNotImplementedError

Columns of arrays / lists are not yet supported.

len(self, **kwargs)

Computes the length of each element in the Series/Index.

ReturnsSeries or Index of int

A Series or Index of integer values indicating the length of each element in the Series or Index.

Examples

>>> import cudf
>>> s = cudf.Series(["dog", "", "\n", None])
>>> s.str.len()
0       3
1       0
2       1
3    null
dtype: int32
ljust(self, width, fillchar=' ', **kwargs)

Filling right side of strings in the Series/Index with an additional character. Equivalent to str.ljust().

Parameters
widthint

Minimum width of resulting string; additional characters will be filled with fillchar.

fillcharstr, default ‘ ‘ (whitespace)

Additional character for filling, default is whitespace.

Returns
Series/Index of str dtype

Returns Series or Index.

Examples

>>> import cudf
>>> s = cudf.Series(["hello world", "rapids ai"])
>>> s.str.ljust(10, fillchar="_")
0    hello world
1     rapids ai_
dtype: object
>>> s = cudf.Series(["a", "",  "ab", "__"])
>>> s.str.ljust(1, fillchar="-")
0     a
1     -
2    ab
3    __
dtype: object
lower(self, **kwargs)

Converts all characters to lowercase.

Equivalent to str.lower().

ReturnsSeries or Index of object

A copy of the object with all strings converted to lowercase.

See also

upper

Converts all characters to uppercase.

title

Converts first character of each word to uppercase and remaining to lowercase.

capitalize

Converts first character to uppercase and remaining to lowercase.

swapcase

Converts uppercase to lowercase and lowercase to uppercase.

Examples

>>> import cudf
>>> data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
>>> s = cudf.Series(data)
>>> s.str.lower()
0                 lower
1              capitals
2    this is a sentence
3              swapcase
dtype: object
lstrip(self, to_strip=None, **kwargs)

Remove leading and trailing characters.

Strip whitespaces (including newlines) or a set of specified characters from each string in the Series/Index from left side. Equivalent to str.lstrip().

Parameters
to_stripstr or None, default None

Specifying the set of characters to be removed. All combinations of this set of characters will be stripped. If None then whitespaces are removed.

Returns
Series or Index of object

See also

strip

Remove leading and trailing characters in Series/Index.

rstrip

Remove trailing characters in Series/Index.

Examples

>>> import cudf
>>> s = cudf.Series(['1. Ant.  ', '2. Bee!\n', '3. Cat?\t', None])
>>> s.str.lstrip('123.')
0     Ant.
1     Bee!\n
2     Cat?\t
3       None
dtype: object
match(self, pat, case=True, flags=0, **kwargs)

Determine if each string matches a regular expression.

Parameters
patstr

Character sequence or regular expression.

Returns
Series or Index of boolean values.

Notes

Parameters currently not supported are: case, flags and na.

Examples

>>> import cudf
>>> s = cudf.Series(["rapids", "ai", "cudf"])

Checking for strings starting with a.

>>> s.str.match('a')
0    False
1     True
2    False
dtype: bool

Checking for strings starting with any of a or c.

>>> s.str.match('[ac]')
0    False
1     True
2     True
dtype: bool
ngrams(self, n=2, separator='_', **kwargs)

Generate the n-grams from a set of tokens, each record in series is treated a token.

You can generate tokens from a Series instance using the Series.str.tokenize() function.

Parameters
nint

The degree of the n-gram (number of consecutive tokens). Default of 2 for bigrams.

separatorstr

The separator to use between within an n-gram. Default is ‘_’.

Examples

>>> import cudf
>>> str_series = cudf.Series(['this is my', 'favorite book'])
>>> str_series = cudf.Series(['this is my', 'favorite book'])
>>> str_series.str.ngrams(2, "_")
0    this is my_favorite book
dtype: object
>>> str_series = cudf.Series(['abc','def','xyz','hhh'])
>>> str_series.str.ngrams(2, "_")
0    abc_def
1    def_xyz
2    xyz_hhh
dtype: object
ngrams_tokenize(self, n=2, delimiter=' ', separator='_', **kwargs)

Generate the n-grams using tokens from each string. This will tokenize each string and then generate ngrams for each string.

Parameters
nint, Default 2.

The degree of the n-gram (number of consecutive tokens).

delimiterstr, Default is white-space.

The character used to locate the split points of each string.

sepstr, Default is ‘_’.

The separator to use between tokens within an n-gram.

Returns
Series or Index of object.

Examples

>>> import cudf
>>> ser = cudf.Series(['this is the', 'best book'])
>>> ser.str.ngrams_tokenize(n=2, sep='_')
0      this_is
1       is_the
2    best_book
dtype: object
normalize_spaces(self, **kwargs)

Remove extra whitespace between tokens and trim whitespace from the beginning and the end of each string.

Returns
Series or Index of object.

Examples

>>> import cudf
>>> ser = cudf.Series(["hello \t world"," test string  "])
>>> ser.str.normalize_spaces()
0    hello world
1    test string
dtype: object
pad(self, width, side='left', fillchar=' ', **kwargs)

Pad strings in the Series/Index up to width.

Parameters
widthint

Minimum width of resulting string; additional characters will be filled with character defined in fillchar.

side{‘left’, ‘right’, ‘both’}, default ‘left’

Side from which to fill resulting string.

fillcharstr, default ‘ ‘ (whitespace)

Additional character for filling, default is whitespace.

Returns
Series/Index of object

Returns Series or Index with minimum number of char in object.

See also

rjust

Fills the left side of strings with an arbitrary character. Equivalent to Series.str.pad(side='left').

ljust

Fills the right side of strings with an arbitrary character. Equivalent to Series.str.pad(side='right').

center

Fills boths sides of strings with an arbitrary character. Equivalent to Series.str.pad(side='both').

zfill

Pad strings in the Series/Index by prepending ‘0’ character. Equivalent to Series.str.pad(side='left', fillchar='0').

Examples

>>> import cudf
>>> s = cudf.Series(["caribou", "tiger"])
>>> s.str.pad(width=10)
0       caribou
1         tiger
dtype: object
>>> s.str.pad(width=10, side='right', fillchar='-')
0    caribou---
1    tiger-----
dtype: object
>>> s.str.pad(width=10, side='both', fillchar='-')
0    -caribou--
1    --tiger---
dtype: object
partition(self, sep=' ', expand=True, **kwargs)

Split the string at the first occurrence of sep.

This method splits the string at the first occurrence of sep, and returns 3 elements containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return 3 elements containing the string itself, followed by two empty strings.

Parameters
sepstr, default ‘ ‘ (whitespace)

String to split on.

Returns
DataFrame or MultiIndex

Returns a DataFrame / MultiIndex

See also

rpartition

Split the string at the last occurrence of sep.

split

Split strings around given separators.

Notes

The parameter expand is not yet supported and will raise a NotImplementedError if anything other than the default value is set.

Examples

>>> import cudf
>>> s = cudf.Series(['Linda van der Berg', 'George Pitt-Rivers'])
>>> s
0    Linda van der Berg
1    George Pitt-Rivers
dtype: object
>>> s.str.partition()
        0  1             2
0   Linda     van der Berg
1  George      Pitt-Rivers

To partition by something different than a space:

>>> s.str.partition('-')
                    0  1       2
0  Linda van der Berg
1         George Pitt  -  Rivers

Also available on indices:

>>> idx = cudf.core.index.StringIndex(['X 123', 'Y 999'])
>>> idx
StringIndex(['X 123' 'Y 999'], dtype='object')

Which will create a MultiIndex:

>>> idx.str.partition()
MultiIndex(levels=[0    X
1    Y
dtype: object, 0
dtype: object, 0    123
1    999
dtype: object],
codes=   0  1  2
0  0  0  0
1  1  0  1)
replace(self, pat, repl, n=- 1, case=None, flags=0, regex=True, **kwargs)

Replace occurrences of pattern/regex in the Series/Index with some other string. Equivalent to str.replace() or re.sub().

Parameters
patstr or list-like

String(s) to be replaced as a character sequence or regular expression.

replstr or list-like

String(s) to be used as replacement.

nint, default -1 (all)

Number of replacements to make from the start.

regexbool, default True

If True, assumes the pattern is a regular expression. If False, treats the pattern as a literal string.

Returns
Series/Index of str dtype

A copy of the object with all matching occurrences of pat replaced by repl.

Notes

The parameters case and flags are not yet supported and will raise a NotImplementedError if anything other than the default value is set.

Examples

>>> import cudf
>>> s = cudf.Series(['foo', 'fuz', None])
>>> s
0     foo
1     fuz
2    None
dtype: object

When pat is a string and regex is True (the default), the given pat is compiled as a regex. When repl is a string, it replaces matching regex patterns as with re.sub(). NaN value(s) in the Series are left as is:

>>> s.str.replace('f.', 'ba', regex=True)
0     bao
1     baz
2    None
dtype: object

When pat is a string and regex is False, every pat is replaced with repl as with str.replace():

>>> s.str.replace('f.', 'ba', regex=False)
0     foo
1     fuz
2    None
dtype: object
replace_tokens(self, targets, replacements, delimiter=None, **kwargs)

The targets tokens are searched for within each string in the series and replaced with the corresponding replacements if found. Tokens are identified by the delimiter character provided.

Parameters
targetsarray-like, Sequence or Series

The tokens to search for inside each string.

replacementsarray-like, Sequence, Series or str

The strings to replace for each found target token found. Alternately, this can be a single str instance and would be used as replacement for each string found.

delimiterstr

The character used to locate the tokens of each string. Default is whitespace.

Returns
Series or Index of object.

Examples

>>> import cudf
>>> sr = cudf.Series(["this is me", "theme music", ""])
>>> targets = cudf.Series(["is", "me"])
>>> sr.str.replace_tokens(targets=targets, replacements="_")
0       this _ _
1    theme music
2
dtype: object
>>> sr = cudf.Series(["this;is;me", "theme;music", ""])
>>> sr.str.replace_tokens(targets=targets, replacements=":")
0     this;is;me
1    theme;music
2
dtype: object
replace_with_backrefs(self, pat, repl, **kwargs)

Use the repl back-ref template to create a new string with the extracted elements found using the pat expression.

Parameters
patstr

Regex with groupings to identify extract sections. This should not be a compiled regex.

replstr

String template containing back-reference indicators.

Returns
Series/Index of str dtype

Examples

>>> import cudf
>>> s = cudf.Series(["A543","Z756"])
>>> s.str.replace_with_backrefs('(\d)(\d)', 'V\2\1')
0    AV453
1    ZV576
dtype: object
rfind(self, sub, start=0, end=None, **kwargs)

Return highest indexes in each strings in the Series/Index where the substring is fully contained between [start:end]. Return -1 on failure. Equivalent to standard str.rfind().

Parameters
substr

Substring being searched.

startint

Left edge index.

endint

Right edge index.

Returns
Series or Index of int

See also

find

Return lowest indexes in each strings.

Examples

>>> import cudf
>>> s = cudf.Series(["abc", "hello world", "rapids ai"])
>>> s.str.rfind('a')
0    0
1   -1
2    7
dtype: int32

Using start and end parameters.

>>> s.str.rfind('a', start=2, end=5)
0   -1
1   -1
2   -1
dtype: int32
rindex(self, sub, start=0, end=None, **kwargs)

Return highest indexes in each strings where the substring is fully contained between [start:end]. This is the same as str.rfind except instead of returning -1, it raises a ValueError when the substring is not found.

Parameters
substr

Substring being searched.

startint

Left edge index.

endint

Right edge index.

Returns
Series or Index of object

Examples

>>> import cudf
>>> s = cudf.Series(['abc', 'a','b' ,'ddb'])
>>> s.str.rindex('b')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found

Parameters such as start and end can also be used.

>>> s = cudf.Series(['abc', 'abb','ab' ,'ddb'])
>>> s.str.rindex('b', start=1, end=5)
0    1
1    2
2    1
3    2
dtype: int32
rjust(self, width, fillchar=' ', **kwargs)

Filling left side of strings in the Series/Index with an additional character. Equivalent to str.rjust().

Parameters
widthint

Minimum width of resulting string; additional characters will be filled with fillchar.

fillcharstr, default ‘ ‘ (whitespace)

Additional character for filling, default is whitespace.

Returns
Series/Index of str dtype

Returns Series or Index.

Examples

>>> import cudf
>>> s = cudf.Series(["hello world", "rapids ai"])
>>> s.str.rjust(20, fillchar="_")
0    _________hello world
1    ___________rapids ai
dtype: object
>>> s = cudf.Series(["a", "",  "ab", "__"])
>>> s.str.rjust(1, fillchar="-")
0     a
1     -
2    ab
3    __
dtype: object
rpartition(self, sep=' ', expand=True, **kwargs)

Split the string at the last occurrence of sep.

This method splits the string at the last occurrence of sep, and returns 3 elements containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return 3 elements containing two empty strings, followed by the string itself.

Parameters
sepstr, default ‘ ‘ (whitespace)

String to split on.

Returns
DataFrame or MultiIndex

Returns a DataFrame / MultiIndex

Notes

The parameter expand is not yet supported and will raise a NotImplementedError if anything other than the default value is set.

Examples

>>> import cudf
>>> s = cudf.Series(['Linda van der Berg', 'George Pitt-Rivers'])
>>> s
0    Linda van der Berg
1    George Pitt-Rivers
dtype: object
>>> s.str.rpartition()
            0  1            2
0  Linda van der            Berg
1         George     Pitt-Rivers

Also available on indices:

>>> idx = cudf.core.index.StringIndex(['X 123', 'Y 999'])
>>> idx
StringIndex(['X 123' 'Y 999'], dtype='object')

Which will create a MultiIndex:

>>> idx.str.rpartition()
MultiIndex(levels=[0    X
1    Y
dtype: object, 0
dtype: object, 0    123
1    999
dtype: object],
codes=   0  1  2
0  0  0  0
1  1  0  1)
rsplit(self, pat=None, n=- 1, expand=None, **kwargs)

Split strings around given separator/delimiter.

Splits the string in the Series/Index from the end, at the specified delimiter string. Equivalent to str.rsplit().

Parameters
patstr, default ‘ ‘ (space)

String to split on, does not yet support regular expressions.

nint, default -1 (all)

Limit number of splits in output. None, 0, and -1 will all be interpreted as “all splits”.

Returns
DataFrame or MultiIndex

Returns a DataFrame/MultiIndex with each split as a column.

See also

split

Split strings around given separator/delimiter.

str.split

Standard library version for split.

str.rsplit

Standard library version for rsplit.

Notes

The parameter expand is not yet supported and will raise a NotImplementedError if anything other than the default value is set. The handling of the n keyword depends on the number of found splits:

  • If found splits > n, make first n splits only

  • If found splits <= n, make all splits

  • If for a certain row the number of found splits < n, append None for padding up to n.

Examples

>>> import cudf
>>> data = ["this is a regular sentence","https://docs.python.org/3/tutorial/index.html",None]      # noqa E501
>>> s = cudf.Series(data)
>>> s.str.rsplit(n=2)
                                               0        1         2
0                                      this is a  regular  sentence
1  https://docs.python.org/3/tutorial/index.html     None      None
2                                           None     None      None

For slightly more complex use cases like splitting the html document name from a url, a combination of parameter settings can be used.

>>> s.str.rsplit("/", n=1, expand=True)
                                    0           1
0          this is a regular sentence        None
1  https://docs.python.org/3/tutorial  index.html
2                                None        None
rstrip(self, to_strip=None, **kwargs)

Remove leading and trailing characters.

Strip whitespaces (including newlines) or a set of specified characters from each string in the Series/Index from right side. Equivalent to str.rstrip().

Parameters
to_stripstr or None, default None

Specifying the set of characters to be removed. All combinations of this set of characters will be stripped. If None then whitespaces are removed.

Returns
Series/Index of str dtype

Returns Series or Index.

See also

strip

Remove leading and trailing characters in Series/Index.

lstrip

Remove leading characters in Series/Index.

Examples

>>> import cudf
>>> s = cudf.Series(['1. Ant.  ', '2. Bee!\n', '3. Cat?\t', None])
>>> s
0    1. Ant.
1    2. Bee!\n
2    3. Cat?\t
3         None
dtype: object
>>> s.str.rstrip('.!? \n\t')
0    1. Ant
1    2. Bee
2    3. Cat
3      None
dtype: object
slice(self, start=None, stop=None, step=None, **kwargs)

Slice substrings from each element in the Series or Index.

Parameters
startint, optional

Start position for slice operation.

stopint, optional

Stop position for slice operation.

stepint, optional

Step size for slice operation.

Returns
Series/Index of str dtype

Series or Index from sliced substring from original string object.

See also

slice_replace

Replace a slice with a string.

get

Return element at position. Equivalent to Series.str.slice(start=i, stop=i+1) with i being the position.

Examples

>>> import cudf
>>> s = cudf.Series(["koala", "fox", "chameleon"])
>>> s
0        koala
1          fox
2    chameleon
dtype: object
>>> s.str.slice(start=1)
0        oala
1          ox
2    hameleon
dtype: object
>>> s.str.slice(start=-1)
0    a
1    x
2    n
dtype: object
>>> s.str.slice(stop=2)
0    ko
1    fo
2    ch
dtype: object
>>> s.str.slice(step=2)
0      kaa
1       fx
2    caeen
dtype: object
>>> s.str.slice(start=0, stop=5, step=3)
0    kl
1     f
2    cm
dtype: object
slice_from(self, starts, stops, **kwargs)

Return substring of each string using positions for each string.

The starts and stops parameters are of Column type.

Parameters
startsSeries

Beginning position of each the string to extract. Default is beginning of the each string.

stopsSeries

Ending position of the each string to extract. Default is end of each string. Use -1 to specify to the end of that string.

Returns
Series/Index of str dtype

A substring of each string using positions for each string.

Examples

>>> import cudf
>>> s = cudf.Series(["hello","there"])
>>> s
0    hello
1    there
dtype: object
>>> starts = cudf.Series([1, 3])
>>> stops = cudf.Series([5, 5])
>>> s.str.slice_from(starts, stops)
0    ello
1      re
dtype: object
slice_replace(self, start=None, stop=None, repl=None, **kwargs)

Replace the specified section of each string with a new string.

Parameters
startint, optional

Beginning position of the string to replace. Default is beginning of the each string.

stopint, optional

Ending position of the string to replace. Default is end of each string.

replstr, optional

String to insert into the specified position values.

Returns
Series/Index of str dtype

A new string with the specified section of the string replaced with repl string.

See also

slice

Just slicing without replacement.

Examples

>>> import cudf
>>> s = cudf.Series(['a', 'ab', 'abc', 'abdc', 'abcde'])
>>> s
0        a
1       ab
2      abc
3     abdc
4    abcde
dtype: object

Specify just start, meaning replace start until the end of the string with repl.

>>> s.str.slice_replace(1, repl='X')
0    aX
1    aX
2    aX
3    aX
4    aX
dtype: object

Specify just stop, meaning the start of the string to stop is replaced with repl, and the rest of the string is included.

>>> s.str.slice_replace(stop=2, repl='X')
0       X
1       X
2      Xc
3     Xdc
4    Xcde
dtype: object

Specify start and stop, meaning the slice from start to stop is replaced with repl. Everything before or after start and stop is included as is.

>>> s.str.slice_replace(start=1, stop=3, repl='X')
0      aX
1      aX
2      aX
3     aXc
4    aXde
dtype: object
split(self, pat=None, n=- 1, expand=None, **kwargs)

Split strings around given separator/delimiter.

Splits the string in the Series/Index from the beginning, at the specified delimiter string. Equivalent to str.split().

Parameters
patstr, default ‘ ‘ (space)

String to split on, does not yet support regular expressions.

nint, default -1 (all)

Limit number of splits in output. None, 0, and -1 will all be interpreted as “all splits”.

Returns
DataFrame

Returns a DataFrame with each split as a column.

See also

rsplit

Splits string around given separator/delimiter, starting from the right.

str.split

Standard library version for split.

str.rsplit

Standard library version for rsplit.

Notes

The parameter expand is not yet supported and will raise a NotImplementedError if anything other than the default value is set. The handling of the n keyword depends on the number of found splits:

  • If found splits > n, make first n splits only

  • If found splits <= n, make all splits

  • If for a certain row the number of found splits < n, append None for padding up to n

Examples

>>> import cudf
>>> data = ["this is a regular sentence", "https://docs.python.org/index.html", None]       # noqa E501
>>> s = cudf.Series(data)
>>> s
0            this is a regular sentence
1    https://docs.python.org/index.html
2                                  None
dtype: object

The n parameter can be used to limit the number of splits on the delimiter.

>>> s.str.split(n=2)
                                    0     1                   2
0                                this    is  a regular sentence
1  https://docs.python.org/index.html  None                None
2                                None  None                None

The pat parameter can be used to split by other characters.

>>> s.str.split(pat = "/")
                            0     1                2           3
0  this is a regular sentence  None             None        None
1                      https:        docs.python.org  index.html
2                        None  None             None        None
startswith(self, pat, **kwargs)

Test if the start of each string element matches a pattern.

Equivalent to str.startswith().

Parameters
patstr or list-like

If str is an str, evaluates whether each string of series starts with pat. If pat is a list-like, evaluates whether self[i] starts with pat[i]. Regular expressions are not accepted.

Returns
Series or Index of bool

A Series of booleans indicating whether the given pattern matches the start of each string element.

See also

endswith

Same as startswith, but tests the end of string.

contains

Tests if string element contains a pattern.

Examples

>>> import cudf
>>> s
0     bat
1    Bear
2     cat
3    None
dtype: object
>>> s.str.startswith('b')
0     True
1    False
2    False
3     null
dtype: bool
strip(self, to_strip=None, **kwargs)

Remove leading and trailing characters.

Strip whitespaces (including newlines) or a set of specified characters from each string in the Series/Index from left and right sides. Equivalent to str.strip().

Parameters
to_stripstr or None, default None

Specifying the set of characters to be removed. All combinations of this set of characters will be stripped. If None then whitespaces are removed.

Returns
Series/Index of str dtype

Returns Series or Index.

See also

lstrip

Remove leading characters in Series/Index.

rstrip

Remove trailing characters in Series/Index.

Examples

>>> import cudf
>>> s = cudf.Series(['1. Ant.  ', '2. Bee!\n', '3. Cat?\t', None])
>>> s
0    1. Ant.
1    2. Bee!\n
2    3. Cat?\t
3         None
dtype: object
>>> s.str.strip()
0    1. Ant.
1    2. Bee!
2    3. Cat?
3       None
dtype: object
>>> s.str.strip('123.!? \n\t')
0     Ant
1     Bee
2     Cat
3    None
dtype: object
swapcase(self, **kwargs)

Change each lowercase character to uppercase and vice versa. This only applies to ASCII characters at this time.

Equivalent to str.swapcase().

Returns : Series or Index of object

See also

lower

Converts all characters to lowercase.

upper

Converts all characters to uppercase.

title

Converts first character of each word to uppercase and remaining to lowercase.

capitalize

Converts first character to uppercase and remaining to lowercase.

Examples

>>> import cudf
>>> data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
>>> s = cudf.Series(data)
>>> s
0                 lower
1              CAPITALS
2    this is a sentence
3              SwApCaSe
dtype: object
>>> s.str.swapcase()
0                 LOWER
1              capitals
2    THIS IS A SENTENCE
3              sWaPcAsE
dtype: object
title(self, **kwargs)

Uppercase the first letter of each letter after a space and lowercase the rest. This only applies to ASCII characters at this time.

Equivalent to str.title().

Returns : Series or Index of object

See also

lower

Converts all characters to lowercase.

upper

Converts all characters to uppercase.

capitalize

Converts first character to uppercase and remaining to lowercase.

swapcase

Converts uppercase to lowercase and lowercase to uppercase.

Examples

>>> import cudf
>>> data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe'])
>>> s = cudf.Series(data)
>>> s
0                 lower
1              CAPITALS
2    this is a sentence
3              SwApCaSe
dtype: object
>>> s.str.title()
0                 Lower
1              Capitals
2    This Is A Sentence
3              Swapcase
dtype: object
token_count(self, delimiter=' ', **kwargs)

Each string is split into tokens using the provided delimiter. The returned integer sequence is the number of tokens in each string.

Parameters
delimiterstr or list of strs, Default is whitespace.

The characters or strings used to locate the split points of each string.

Returns
Series or Index.

Examples

>>> import cudf
>>> ser = cudf.Series(["hello world","goodbye",""])
>>> ser.str.token_count()
0    2
1    1
2    0
dtype: int32
tokenize(self, delimiter=' ', **kwargs)

Each string is split into tokens using the provided delimiter(s). The sequence returned contains the tokens in the order they were found.

Parameters
delimiterstr or list of strs, Default is whitespace.

The string used to locate the split points of each string.

Returns
Series or Index of object.

Examples

>>> import cudf
>>> data = ["hello world", "goodbye world", "hello goodbye"]
>>> ser = cudf.Series(data)
>>> ser.str.tokenize()
0      hello
1      world
2    goodbye
3      world
4      hello
5    goodbye
dtype: object
translate(self, table, **kwargs)

Map all characters in the string through the given mapping table.

Equivalent to standard str.translate().

Parameters
tabledict

Table is a mapping of Unicode ordinals to Unicode ordinals, strings, or None. Unmapped characters are left untouched. str.maketrans() is a helper function for making translation tables.

Returns
Series or Index.

Examples

>>> import cudf
>>> data = ['lower', 'CAPITALS', 'this is a sentence','SwApCaSe']
>>> s = cudf.Series(data)
>>> s.str.translate({'a': "1"})
0                 lower
1              CAPITALS
2    this is 1 sentence
3              SwApC1Se
dtype: object
>>> s.str.translate({'a': "1", "e":"#"})
0                 low#r
1              CAPITALS
2    this is 1 s#nt#nc#
3              SwApC1S#
dtype: object
upper(self, **kwargs)

Convert each string to uppercase. This only applies to ASCII characters at this time.

Equivalent to str.upper().

Returns : Series or Index of object

See also

lower

Converts all characters to lowercase.

upper

Converts all characters to uppercase.

title

Converts first character of each word to uppercase and remaining to lowercase.

capitalize

Converts first character to uppercase and remaining to lowercase.

swapcase

Converts uppercase to lowercase and lowercase to uppercase.

Examples

>>> import cudf
>>> data = ['lower', 'CAPITALS', 'this is a sentence', 'SwApCaSe']
>>> s = cudf.Series(data)
>>> s
0                 lower
1              CAPITALS
2    this is a sentence
3              SwApCaSe
dtype: object
>>> s.str.upper()
0                 LOWER
1              CAPITALS
2    THIS IS A SENTENCE
3              SWAPCASE
dtype: object
url_decode(self, **kwargs)

Returns a URL-decoded format of each string. No format checking is performed. All characters are expected to be encoded as UTF-8 hex values.

Returns
Series or Index.

Examples

>>> import cudf
>>> s = cudf.Series(['A%2FB-C%2FD', 'e%20f.g', '4-5%2C6'])
>>> s.str.url_decode()
0    A/B-C/D
1      e f.g
2      4-5,6
dtype: object
>>> data = ["https%3A%2F%2Frapids.ai%2Fstart.html", "https%3A%2F%2Fmedium.com%2Frapids-ai"]     # noqa E501
>>> s = cudf.Series(data)
>>> s.str.url_decode()
0    https://rapids.ai/start.html
1    https://medium.com/rapids-ai
dtype: object
url_encode(self, **kwargs)

Returns a URL-encoded format of each string. No format checking is performed. All characters are encoded except for ASCII letters, digits, and these characters: ‘.’,’_’,’-‘,’~’. Encoding converts to hex using UTF-8 encoded bytes.

Returns
Series or Index.

Examples

>>> import cudf
>>> s = cudf.Series(['A/B-C/D', 'e f.g', '4-5,6'])
>>> s.str.url_encode()
0    A%2FB-C%2FD
1        e%20f.g
2        4-5%2C6
dtype: object
>>> data = ["https://rapids.ai/start.html", "https://medium.com/rapids-ai"]         # noqa E501
>>> s = cudf.Series(data)
>>> s.str.url_encode()
0    https%3A%2F%2Frapids.ai%2Fstart.html
1    https%3A%2F%2Fmedium.com%2Frapids-ai
dtype: object
wrap(self, width, **kwargs)

Wrap long strings in the Series/Index to be formatted in paragraphs with length less than a given width.

Parameters
widthint

Maximum line width.

Returns
Series or Index

Notes

The parameters expand_tabsbool, replace_whitespace, drop_whitespace, break_long_words, break_on_hyphens, expand_tabsbool are not yet supported and will raise a NotImplementedError if they are set to any value.

This method currently achieves behavior matching R’s stringr library str_wrap function, the equivalent pandas implementation can be obtained using the following parameter setting:

expand_tabs = False

replace_whitespace = True

drop_whitespace = True

break_long_words = False

break_on_hyphens = False

Examples

>>> import cudf
>>> data = ['line to be wrapped', 'another line to be wrapped']
>>> s = cudf.Series(data)
>>> s.str.wrap(12)
0             line to be\nwrapped
1    another line\nto be\nwrapped
dtype: object
zfill(self, width, **kwargs)

Pad strings in the Series/Index by prepending ‘0’ characters.

Strings in the Series/Index are padded with ‘0’ characters on the left of the string to reach a total string length width. Strings in the Series/Index with length greater or equal to width are unchanged.

Parameters
widthint

Minimum length of resulting string; strings with length less than width be prepended with ‘0’ characters.

Returns
Series/Index of str dtype

Returns Series or Index with prepended ‘0’ characters.

See also

rjust

Fills the left side of strings with an arbitrary character.

ljust

Fills the right side of strings with an arbitrary character.

pad

Fills the specified sides of strings with an arbitrary character.

center

Fills boths sides of strings with an arbitrary character.

Notes

Differs from str.zfill() which has special handling for ‘+’/’-‘ in the string.

Examples

>>> import cudf
>>> s = cudf.Series(['-1', '1', '1000',  None])
>>> s
0      -1
1       1
2    1000
3    None
dtype: object

Note that None is not string, therefore it is converted to None. The minus sign in '-1' is treated as a regular character and the zero is added to the left of it (str.zfill() would have moved it to the left). 1000 remains unchanged as it is longer than width.

>>> s.str.zfill(3)
0     0-1
1     001
2    1000
3    None
dtype: object

Index

class cudf.core.index.Index(data=None, dtype=None, copy=False, name=None, tupleize_cols=True, **kwargs)

Immutable, ordered and sliceable sequence of integer labels. The basic object storing row labels for all cuDF objects.

Returns
Index

cudf Index

Examples

>>> import cudf
>>> cudf.Index([1, 2, 3], dtype="uint64", name="a")
UInt64Index([1, 2, 3], dtype='uint64', name='a')
>>> cudf.Index(cudf.DataFrame({"a":[1, 2], "b":[2, 3]}))
MultiIndex(levels=[0    1
1    2
dtype: int64, 0    2
1    3
dtype: int64],
codes=   a  b
0  0  0
1  1  1)
Attributes
gpu_values

View the data as a numba device array object

is_unique

Return if the index has unique values.

name

Returns the name of the Index.

names

Returns a tuple containing the name of the Index.

ndim

Dimension of the data.

values

Return an array representing the data in the Index.

Methods

any(self)

Return whether any elements is True in Index.

argsort(self[, ascending])

Return the integer indices that would sort the index.

astype(self, dtype[, copy])

Create an Index with values cast to dtypes.

dropna(self)

Return a Series with null values removed.

equals(self, other)

Determine if two Index objects contain the same elements.

from_pandas(index[, nan_as_null])

Convert from a Pandas Index.

get_level_values(self, level)

Return an Index of values for requested level.

get_slice_bound(self, label, side, kind)

Calculate slice bound that corresponds to given label.

isin(self, values)

Return a boolean array where the index values are in values.

join(self, other[, how, level, …])

Compute join_index and indexers to conform data structures to the new index.

max(self)

Return the maximum value of the Index.

memory_usage(self[, deep])

Memory usage of the values.

min(self)

Return the minimum value of the Index.

rename(self, name[, inplace])

Alter Index name.

sum(self)

Return the sum of all values of the Index.

take(self, indices)

Gather only the specific subset of indices

to_array(self[, fillna])

Get a dense numpy array for the data.

to_arrow(self)

Convert Index to a PyArrow Array.

to_dlpack(self)

Converts a cuDF object into a DLPack tensor.

to_pandas(self)

Convert to a Pandas Index.

to_series(self[, index, name])

Create a Series with both index and values equal to the index keys.

unique(self)

Return unique values in the index.

where(self, cond[, other])

Replace values where the condition is False.

any(self)

Return whether any elements is True in Index.

argsort(self, ascending=True, **kwargs)

Return the integer indices that would sort the index.

Parameters
ascendingbool, default True

If True, returns the indices for ascending order. If False, returns the indices for descending order.

Returns
arrayA cupy array containing Integer indices that

would sort the index if used as an indexer.

astype(self, dtype, copy=False)

Create an Index with values cast to dtypes. The class of a new Index is determined by dtype. When conversion is impossible, a ValueError exception is raised.

Parameters
dtypenumpy dtype

Use a numpy.dtype to cast entire Index object to.

copybool, default False

By default, astype always returns a newly allocated object. If copy is set to False and internal requirements on dtype are satisfied, the original data is used to create a new Index or the original Index is returned.

Returns
Index

Index with values cast to specified dtype.

dropna(self)

Return a Series with null values removed.

equals(self, other)

Determine if two Index objects contain the same elements.

Returns
out: bool

True if “other” is an Index and it has the same elements as calling index; False otherwise.

classmethod from_pandas(index, nan_as_null=None)

Convert from a Pandas Index.

Parameters
indexPandas Index object

A Pandas Index object which has to be converted to cuDF Index.

nan_as_nullbool, Default None

If None/True, converts np.nan values to null values. If False, leaves np.nan values as is.

Raises
TypeError for invalid input type.

Examples

>>> import cudf
>>> import pandas as pd
>>> import numpy as np
>>> data = [10, 20, 30, np.nan]
>>> pdi = pd.Index(data)
>>> cudf.core.index.Index.from_pandas(pdi)
Index(['10.0', '20.0', '30.0', 'null'], dtype='object')
>>> cudf.core.index.Index.from_pandas(pdi, nan_as_null=False)
Float64Index([10.0, 20.0, 30.0, nan], dtype='float64')
get_level_values(self, level)

Return an Index of values for requested level.

This is primarily useful to get an individual level of values from a MultiIndex, but is provided on Index as well for compatibility.

Parameters
levelint or str

It is either the integer position or the name of the level.

Returns
Index

Calling object, as there is only one level in the Index.

See also

cudf.core.multiindex.get_level_values

Get values for a level of a MultiIndex.

Notes

For Index, level should be 0, since there are no multiple levels.

Examples

>>> import cudf
>>> idx = cudf.core.index.StringIndex(["a","b","c"])
>>> idx.get_level_values(0)
StringIndex(['a' 'b' 'c'], dtype='object')
get_slice_bound(self, label, side, kind)

Calculate slice bound that corresponds to given label. Returns leftmost (one-past-the-rightmost if side=='right') position of given label.

Parameters
labelobject
side{‘left’, ‘right’}
kind{‘ix’, ‘loc’, ‘getitem’}
Returns
int

Index of label.

property gpu_values

View the data as a numba device array object

property is_unique

Return if the index has unique values.

isin(self, values)

Return a boolean array where the index values are in values.

Compute boolean array of whether each index value is found in the passed set of values. The length of the returned boolean array matches the length of the index.

Parameters
valuesset, list-like, Index

Sought values.

Returns
is_containedcupy array

CuPy array of boolean values.

join(self, other, how='left', level=None, return_indexers=False, sort=False)

Compute join_index and indexers to conform data structures to the new index.

Parameters
otherIndex.
how{‘left’, ‘right’, ‘inner’, ‘outer’}
return_indexersbool, default False
sortbool, default False

Sort the join keys lexicographically in the result Index. If False, the order of the join keys depends on the join type (how keyword).

Returns: index

Examples

>>> import cudf
>>> lhs = cudf.DataFrame(
...     {"a":[2, 3, 1], "b":[3, 4, 2]}).set_index(['a', 'b']
... ).index
>>> rhs = cudf.DataFrame({"a":[1, 4, 3]}).set_index('a').index
>>> lhs.join(rhs, how='inner')
MultiIndex(levels=[0    1
1    3
dtype: int64, 0    2
1    4
dtype: int64],
codes=   a  b
0  1  1
1  0  0)
max(self)

Return the maximum value of the Index.

Returns
scalar

Maximum value.

See also

Index.min

Return the minimum value in an Index.

cudf.core.series.Series.max

Return the maximum value in a Series.

cudf.core.dataframe.Dataframe.max

Return the maximum values in a DataFrame.

Examples

>>> import cudf
>>> idx = cudf.core.index.as_index([3, 2, 1])
>>> idx.max()
3
memory_usage(self, deep=False)

Memory usage of the values.

Parameters
deepbool

Introspect the data deeply, interrogate object dtypes for system-level memory consumption.

Returns
bytes used
min(self)

Return the minimum value of the Index.

Returns
scalar

Minimum value.

See also

Index.max

Return the maximum value in an Index.

cudf.core.series.Series.min

Return the minimum value in a Series.

cudf.core.dataframe.DataFrame.min

Return the minimum values in a DataFrame.

Examples

>>> import cudf
>>> idx = cudf.core.index.as_index([3, 2, 1])
>>> idx.min()
1
property name

Returns the name of the Index.

property names

Returns a tuple containing the name of the Index.

property ndim

Dimension of the data. Apart from MultiIndex ndim is always 1.

rename(self, name, inplace=False)

Alter Index name.

Defaults to returning new index.

Parameters
namelabel

Name(s) to set.

Returns
Index
sum(self)

Return the sum of all values of the Index.

Returns
scalar

Sum of all values.

Examples

>>> import cudf
>>> idx = cudf.core.index.as_index([3, 2, 1])
>>> idx.sum()
6
take(self, indices)

Gather only the specific subset of indices

Parameters
indices: An array-like that maps to values contained in this Index.
to_array(self, fillna=None)

Get a dense numpy array for the data.

Parameters
fillnastr or None

Defaults to None, which will skip null values. If it equals “pandas”, null values are filled with NaNs. Non integral dtype is promoted to np.float64.

Notes

if fillna is None, null values are skipped. Therefore, the output size could be smaller.

to_arrow(self)

Convert Index to a PyArrow Array.

Examples

>>> import cudf
>>> idx = cudf.core.index.as_index([-3, 10, 15, 20])
>>> idx.to_arrow()
<pyarrow.lib.Int64Array object at 0x7fcaa6f53440>
[
-3,
10,
15,
20
]
to_dlpack(self)

Converts a cuDF object into a DLPack tensor.

DLPack is an open-source memory tensor structure: dmlc/dlpack.

This function takes a cuDF object and converts it to a PyCapsule object which contains a pointer to a DLPack tensor. This function deep copies the data into the DLPack tensor from the cuDF object.

Parameters
cudf_objDataFrame, Series, Index, or Column
Returns
pycapsule_objPyCapsule

Output DLPack tensor pointer which is encapsulated in a PyCapsule object.

to_pandas(self)

Convert to a Pandas Index.

Examples

>>> import cudf
>>> idx = cudf.core.index.as_index([-3, 10, 15, 20])
>>> idx
Int64Index([-3, 10, 15, 20], dtype='int64')
>>> idx.to_pandas()
Int64Index([-3, 10, 15, 20], dtype='int64')
>>> type(idx.to_pandas())
<class 'pandas.core.indexes.numeric.Int64Index'>
>>> type(idx)
<class 'cudf.core.index.GenericIndex'>
to_series(self, index=None, name=None)

Create a Series with both index and values equal to the index keys. Useful with map for returning an indexer based on an index.

Parameters
indexIndex, optional

Index of resulting Series. If None, defaults to original index.

namestr, optional

Dame of resulting Series. If None, defaults to name of original index.

Returns
Series

The dtype will be based on the type of the Index values.

unique(self)

Return unique values in the index.

Returns
Index without duplicates
property values

Return an array representing the data in the Index.

Returns
arrayA cupy array of data in the Index.
where(self, cond, other=None)

Replace values where the condition is False.

Parameters
condbool array-like with the same length as self

Where cond is True, keep the original value. Where False, replace with corresponding value from other. Callables are not supported.

other: scalar, or array-like

Entries where cond is False are replaced with corresponding value from other. Callables are not supported. Default is None.

Returns
Same type as caller

RangeIndex

class cudf.core.index.RangeIndex(start, stop=None, step=None, dtype=None, copy=False, name=None)

Immutable, ordered and sliceable sequence of integer labels. The basic object storing row labels for all cuDF objects.

Returns
Index

cudf Index

Examples

>>> import cudf
>>> cudf.Index([1, 2, 3], dtype="uint64", name="a")
UInt64Index([1, 2, 3], dtype='uint64', name='a')
>>> cudf.Index(cudf.DataFrame({"a":[1, 2], "b":[2, 3]}))
MultiIndex(levels=[0    1
1    2
dtype: int64, 0    2
1    3
dtype: int64],
codes=   a  b
0  0  0
1  1  1)
Attributes
dtype

dtype of the range of values in RangeIndex.

is_contiguous

Returns if the index is contiguous.

is_monotonic_decreasing

Return if the index is monotonic decreasing (only equal or decreasing) values.

is_monotonic_increasing

Return if the index is monotonic increasing (only equal or increasing) values.

is_unique

Return if the index has unique values.

name

Returns the name of the Index.

size

Return the number of elements in the underlying data.

start

The value of the start parameter (0 if this was not supplied).

stop

The value of the stop parameter.

Methods

copy(self[, deep])

Make a copy of this object.

equals(self, other)

Determine if two Index objects contain the same elements.

find_label_range(self, first, last)

Find range that starts with first and ends with last, inclusively.

get_slice_bound(self, label, side, kind)

Calculate slice bound that corresponds to given label.

memory_usage(self, **kwargs)

Memory usage of the values.

to_frame(self[, index, name])

Create a DataFrame with a column containing this Index

to_gpu_array(self[, fillna])

Get a dense numba device array for the data.

to_pandas(self)

Convert to a Pandas Index.

unique(self)

Return unique values in the index.

copy(self, deep=True)

Make a copy of this object.

property dtype

dtype of the range of values in RangeIndex.

equals(self, other)

Determine if two Index objects contain the same elements.

Returns
out: bool

True if “other” is an Index and it has the same elements as calling index; False otherwise.

find_label_range(self, first, last)

Find range that starts with first and ends with last, inclusively.

Returns
begin, end2-tuple of int

The starting index and the ending index. The last value occurs at end - 1 position.

get_slice_bound(self, label, side, kind)

Calculate slice bound that corresponds to given label. Returns leftmost (one-past-the-rightmost if side=='right') position of given label.

Parameters
labelobject
side{‘left’, ‘right’}
kind{‘ix’, ‘loc’, ‘getitem’}
Returns
int

Index of label.

property is_contiguous

Returns if the index is contiguous. True incase of RangeIndex.

property is_monotonic_decreasing

Return if the index is monotonic decreasing (only equal or decreasing) values.

property is_monotonic_increasing

Return if the index is monotonic increasing (only equal or increasing) values.

property is_unique

Return if the index has unique values.

memory_usage(self, **kwargs)

Memory usage of the values.

Parameters
deepbool

Introspect the data deeply, interrogate object dtypes for system-level memory consumption.

Returns
bytes used
property name

Returns the name of the Index.

property size

Return the number of elements in the underlying data.

property start

The value of the start parameter (0 if this was not supplied).

property stop

The value of the stop parameter.

to_frame(self, index=True, name=None)

Create a DataFrame with a column containing this Index

Parameters
indexboolean, default True

Set the index of the returned DataFrame as the original Index

namestr, default None

Name to be used for the column

Returns
DataFrame

cudf DataFrame

to_gpu_array(self, fillna=None)

Get a dense numba device array for the data.

Parameters
fillnastr or None

Replacement value to fill in place of nulls.

Notes

if fillna is None, null values are skipped. Therefore, the output size could be smaller.

to_pandas(self)

Convert to a Pandas Index.

Examples

>>> import cudf
>>> idx = cudf.core.index.as_index([-3, 10, 15, 20])
>>> idx
Int64Index([-3, 10, 15, 20], dtype='int64')
>>> idx.to_pandas()
Int64Index([-3, 10, 15, 20], dtype='int64')
>>> type(idx.to_pandas())
<class 'pandas.core.indexes.numeric.Int64Index'>
>>> type(idx)
<class 'cudf.core.index.GenericIndex'>
unique(self)

Return unique values in the index.

Returns
Index without duplicates

GenericIndex

class cudf.core.index.GenericIndex(values, **kwargs)

Immutable, ordered and sliceable sequence of integer labels. The basic object storing row labels for all cuDF objects.

Returns
Index

cudf Index

Examples

>>> import cudf
>>> cudf.Index([1, 2, 3], dtype="uint64", name="a")
UInt64Index([1, 2, 3], dtype='uint64', name='a')
>>> cudf.Index(cudf.DataFrame({"a":[1, 2], "b":[2, 3]}))
MultiIndex(levels=[0    1
1    2
dtype: int64, 0    2
1    3
dtype: int64],
codes=   a  b
0  0  0
1  1  1)
Attributes
dtype

dtype of the underlying values in GenericIndex.

is_monotonic

Alias for is_monotonic_increasing.

is_monotonic_decreasing

Return if the index is monotonic decreasing (only equal or decreasing) values.

is_monotonic_increasing

Return if the index is monotonic increasing (only equal or increasing) values.

is_unique

Return if the index has unique values.

Methods

copy(self[, deep])

Make a copy of this object.

find_label_range(self, first, last)

Find range that starts with first and ends with last, inclusively.

get_slice_bound(self, label, side, kind)

Calculate slice bound that corresponds to given label.

to_frame(self[, index, name])

Create a DataFrame with a column containing this Index

copy(self, deep=True)

Make a copy of this object.

Parameters
deepbool, default True

Make a deep copy of the data. With deep=False the is not copied.

Returns
copyIndex
property dtype

dtype of the underlying values in GenericIndex.

find_label_range(self, first, last)

Find range that starts with first and ends with last, inclusively.

Returns
begin, end2-tuple of int

The starting index and the ending index. The last value occurs at end - 1 position.

get_slice_bound(self, label, side, kind)

Calculate slice bound that corresponds to given label. Returns leftmost (one-past-the-rightmost if side=='right') position of given label.

Parameters
labelobject
side{‘left’, ‘right’}
kind{‘ix’, ‘loc’, ‘getitem’}
Returns
int

Index of label.

property is_monotonic

Alias for is_monotonic_increasing.

property is_monotonic_decreasing

Return if the index is monotonic decreasing (only equal or decreasing) values.

property is_monotonic_increasing

Return if the index is monotonic increasing (only equal or increasing) values.

property is_unique

Return if the index has unique values.

to_frame(self, index=True, name=None)

Create a DataFrame with a column containing this Index

Parameters
indexboolean, default True

Set the index of the returned DataFrame as the original Index

namestr, default None

Name to be used for the column

Returns
DataFrame

cudf DataFrame

Int8Index

class cudf.core.index.Int8Index(data</