Trait polars_core::prelude::SeriesTrait[][src]

pub trait SeriesTrait: Send + Sync + PrivateSeries + PrivateSeriesNumeric {
Show 110 methods fn interpolate(&self) -> Series;
fn rename(&mut self, name: &str);
fn take_every(&self, n: usize) -> Series;
fn sample_n(&self, n: usize, with_replacement: bool) -> Result<Series>;
fn sample_frac(&self, frac: f64, with_replacement: bool) -> Result<Series>; fn bitand(&self, _other: &Series) -> Result<Series> { ... }
fn bitor(&self, _other: &Series) -> Result<Series> { ... }
fn bitxor(&self, _other: &Series) -> Result<Series> { ... }
fn chunk_lengths(&self) -> ChunkIdIter<'_> { ... }
fn name(&self) -> &str { ... }
fn field(&self) -> Cow<'_, Field> { ... }
fn dtype(&self) -> &DataType { ... }
fn chunks(&self) -> &Vec<ArrayRef> { ... }
fn n_chunks(&self) -> usize { ... }
fn shrink_to_fit(&mut self) { ... }
fn i8(&self) -> Result<&Int8Chunked> { ... }
fn i16(&self) -> Result<&Int16Chunked> { ... }
fn i32(&self) -> Result<&Int32Chunked> { ... }
fn i64(&self) -> Result<&Int64Chunked> { ... }
fn f32(&self) -> Result<&Float32Chunked> { ... }
fn f64(&self) -> Result<&Float64Chunked> { ... }
fn u8(&self) -> Result<&UInt8Chunked> { ... }
fn u16(&self) -> Result<&UInt16Chunked> { ... }
fn u32(&self) -> Result<&UInt32Chunked> { ... }
fn u64(&self) -> Result<&UInt64Chunked> { ... }
fn bool(&self) -> Result<&BooleanChunked> { ... }
fn utf8(&self) -> Result<&Utf8Chunked> { ... }
fn time(&self) -> Result<&TimeChunked> { ... }
fn date(&self) -> Result<&DateChunked> { ... }
fn datetime(&self) -> Result<&DatetimeChunked> { ... }
fn list(&self) -> Result<&ListChunked> { ... }
fn categorical(&self) -> Result<&CategoricalChunked> { ... }
fn is_numeric_physical(&self) -> bool { ... }
fn is_numeric(&self) -> bool { ... }
fn append_array(&mut self, _other: ArrayRef) -> Result<()> { ... }
fn limit(&self, num_elements: usize) -> Series { ... }
fn slice(&self, _offset: i64, _length: usize) -> Series { ... }
fn append(&mut self, _other: &Series) -> Result<()> { ... }
fn filter(&self, _filter: &BooleanChunked) -> Result<Series> { ... }
fn take_iter(&self, _iter: &mut dyn TakeIterator) -> Result<Series> { ... }
unsafe fn take_iter_unchecked(&self, _iter: &mut dyn TakeIterator) -> Series { ... }
unsafe fn take_unchecked(&self, _idx: &UInt32Chunked) -> Result<Series> { ... }
unsafe fn take_opt_iter_unchecked(
        &self,
        _iter: &mut dyn TakeIteratorNulls
    ) -> Series { ... }
fn take(&self, _indices: &UInt32Chunked) -> Result<Series> { ... }
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
fn rechunk(&self) -> Series { ... }
fn head(&self, _length: Option<usize>) -> Series { ... }
fn tail(&self, _length: Option<usize>) -> Series { ... }
fn drop_nulls(&self) -> Series { ... }
fn mean(&self) -> Option<f64> { ... }
fn median(&self) -> Option<f64> { ... }
fn expand_at_index(&self, _index: usize, _length: usize) -> Series { ... }
fn cast(&self, _data_type: &DataType) -> Result<Series> { ... }
fn to_dummies(&self) -> Result<DataFrame> { ... }
fn value_counts(&self) -> Result<DataFrame> { ... }
fn get(&self, _index: usize) -> AnyValue<'_> { ... }
unsafe fn get_unchecked(&self, _index: usize) -> AnyValue<'_> { ... }
fn sort_in_place(&mut self, _reverse: bool) { ... }
fn sort(&self, _reverse: bool) -> Series { ... }
fn argsort(&self, _reverse: bool) -> UInt32Chunked { ... }
fn null_count(&self) -> usize { ... }
fn unique(&self) -> Result<Series> { ... }
fn n_unique(&self) -> Result<usize> { ... }
fn arg_unique(&self) -> Result<UInt32Chunked> { ... }
fn arg_min(&self) -> Option<usize> { ... }
fn arg_max(&self) -> Option<usize> { ... }
fn arg_true(&self) -> Result<UInt32Chunked> { ... }
fn is_null(&self) -> BooleanChunked { ... }
fn is_not_null(&self) -> BooleanChunked { ... }
fn is_unique(&self) -> Result<BooleanChunked> { ... }
fn is_duplicated(&self) -> Result<BooleanChunked> { ... }
fn reverse(&self) -> Series { ... }
fn as_single_ptr(&mut self) -> Result<usize> { ... }
fn shift(&self, _periods: i64) -> Series { ... }
fn fill_null(&self, _strategy: FillNullStrategy) -> Result<Series> { ... }
fn sum_as_series(&self) -> Series { ... }
fn max_as_series(&self) -> Series { ... }
fn min_as_series(&self) -> Series { ... }
fn mean_as_series(&self) -> Series { ... }
fn median_as_series(&self) -> Series { ... }
fn var_as_series(&self) -> Series { ... }
fn std_as_series(&self) -> Series { ... }
fn quantile_as_series(&self, _quantile: f64) -> Result<Series> { ... }
fn fmt_list(&self) -> String { ... }
fn hour(&self) -> Result<UInt32Chunked> { ... }
fn minute(&self) -> Result<UInt32Chunked> { ... }
fn second(&self) -> Result<UInt32Chunked> { ... }
fn nanosecond(&self) -> Result<UInt32Chunked> { ... }
fn day(&self) -> Result<UInt32Chunked> { ... }
fn weekday(&self) -> Result<UInt32Chunked> { ... }
fn week(&self) -> Result<UInt32Chunked> { ... }
fn ordinal_day(&self) -> Result<UInt32Chunked> { ... }
fn month(&self) -> Result<UInt32Chunked> { ... }
fn year(&self) -> Result<Int32Chunked> { ... }
fn strftime(&self, fmt: &str) -> Result<Series> { ... }
fn timestamp(&self) -> Result<Int64Chunked> { ... }
fn clone_inner(&self) -> Arc<dyn SeriesTrait> { ... }
fn get_object(&self, _index: usize) -> Option<&dyn PolarsObjectSafe> { ... }
fn as_any(&self) -> &dyn Any { ... }
fn pow(&self, _exponent: f64) -> Result<Series> { ... }
fn peak_max(&self) -> BooleanChunked { ... }
fn peak_min(&self) -> BooleanChunked { ... }
fn is_in(&self, _other: &Series) -> Result<BooleanChunked> { ... }
fn repeat_by(&self, _by: &UInt32Chunked) -> ListChunked { ... }
fn checked_div(&self, _rhs: &Series) -> Result<Series> { ... }
fn is_first(&self) -> Result<BooleanChunked> { ... }
fn mode(&self) -> Result<Series> { ... }
fn rolling_apply(
        &self,
        _window_size: usize,
        _f: &dyn Fn(&Series) -> Series
    ) -> Result<Series> { ... }
fn str_concat(&self, _delimiter: &str) -> Utf8Chunked { ... }
}

Required methods

This is supported on crate feature interpolate only.

Rename the Series.

Take every nth value as a new Series

This is supported on crate feature random only.

Sample n datapoints from this Series.

This is supported on crate feature random only.

Sample a fraction between 0.0-1.0 of this Series.

Provided methods

Get the lengths of the underlying chunks

Name of series.

Get field (used in schema)

Get datatype of series.

Underlying chunks.

Number of chunks in this Series

Shrink the capacity of this array to fit it’s length.

Unpack to ChunkedArray of dtype i8

Unpack to ChunkedArray i16

Unpack to ChunkedArray

let s: Series = [1, 2, 3].iter().collect();
let s_squared: Series = s.i32()
    .unwrap()
    .into_iter()
    .map(|opt_v| {
        match opt_v {
            Some(v) => Some(v * v),
            None => None, // null value
        }
}).collect();

Unpack to ChunkedArray of dtype i64

Unpack to ChunkedArray of dtype f32

Unpack to ChunkedArray of dtype f64

Unpack to ChunkedArray of dtype u8

Unpack to ChunkedArray of dtype u16

Unpack to ChunkedArray of dtype u32

Unpack to ChunkedArray of dtype u64

Unpack to ChunkedArray of dtype bool

Unpack to ChunkedArray of dtype utf8

Unpack to ChunkedArray of dtype Time

Unpack to ChunkedArray of dtype Date

Unpack to ChunkedArray of dtype datetime

Unpack to ChunkedArray of dtype list

Unpack to ChunkedArray of dtype categorical

Check if underlying physical data is numeric.

Date types and Categoricals are also considered numeric.

Check if underlying data is numeric

Append Arrow array of same dtype to this Series.

Take num_elements from the top as a zero copy view.

Get a zero copy view of the data.

When offset is negative the offset is counted from the end of the array

Append a Series of the same type in place.

Filter by boolean mask. This operation clones data.

Take by index from an iterator. This operation clones the data.

Take by index from an iterator. This operation clones the data.

Safety

This doesn’t check any bounds.

Take by index if ChunkedArray contains a single chunk.

Safety

This doesn’t check any bounds.

Take by index from an iterator. This operation clones the data.

Safety

This doesn’t check any bounds.

Take by index. This operation is clone.

Get length of series.

Check if Series is empty.

Aggregate all chunks to a contiguous array of memory.

Get the head of the Series.

Get the tail of the Series.

Drop all null values and return a new Series.

Returns the mean value in the array Returns an option because the array is nullable.

Returns the median value in the array Returns an option because the array is nullable.

Create a new Series filled with values at that index.

Example
use polars_core::prelude::*;
let s = Series::new("a", [0i32, 1, 8]);
let expanded = s.expand_at_index(2, 4);
assert_eq!(Vec::from(expanded.i32().unwrap()), &[Some(8), Some(8), Some(8), Some(8)])

Create dummy variables. See DataFrame

Get a single value by index. Don’t use this operation for loops as a runtime cast is needed for every iteration.

Get a single value by index. Don’t use this operation for loops as a runtime cast is needed for every iteration.

Safety

Does not do any bounds checking

Sort in place.

Retrieve the indexes needed for a sort.

Count the null values.

Get unique values in the Series.

Get unique values in the Series.

Get first indexes of unique values.

Get min index

Get max index

Get indexes that evaluate true

Get a mask of the null values.

Get a mask of the non-null values.

Get a mask of all the unique values.

Get a mask of all the duplicated values.

return a Series in reversed order

Rechunk and return a pointer to the start of the Series. Only implemented for numeric types

Shift the values by a given period and fill the parts that will be empty due to this operation with Nones.

NOTE: If you want to fill the Nones with a value use the shift operation on ChunkedArray<T>.

Example
fn example() -> Result<()> {
    let s = Series::new("series", &[1, 2, 3]);

    let shifted = s.shift(1);
    assert_eq!(Vec::from(shifted.i32()?), &[None, Some(1), Some(2)]);

    let shifted = s.shift(-1);
    assert_eq!(Vec::from(shifted.i32()?), &[Some(2), Some(3), None]);

    let shifted = s.shift(2);
    assert_eq!(Vec::from(shifted.i32()?), &[None, None, Some(1)]);

    Ok(())
}
example();

Replace None values with one of the following strategies:

  • Forward fill (replace None with the previous value)
  • Backward fill (replace None with the next value)
  • Mean fill (replace None with the mean of the whole array)
  • Min fill (replace None with the minimum of the whole array)
  • Max fill (replace None with the maximum of the whole array)

NOTE: If you want to fill the Nones with a value use the fill_null operation on ChunkedArray<T>.

Example
fn example() -> Result<()> {
    let s = Series::new("some_missing", &[Some(1), None, Some(2)]);

    let filled = s.fill_null(FillNullStrategy::Forward)?;
    assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(1), Some(2)]);

    let filled = s.fill_null(FillNullStrategy::Backward)?;
    assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(2), Some(2)]);

    let filled = s.fill_null(FillNullStrategy::Min)?;
    assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(1), Some(2)]);

    let filled = s.fill_null(FillNullStrategy::Max)?;
    assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(2), Some(2)]);

    let filled = s.fill_null(FillNullStrategy::Mean)?;
    assert_eq!(Vec::from(filled.i32()?), &[Some(1), Some(1), Some(2)]);

    Ok(())
}
example();

Get the sum of the Series as a new Series of length 1.

Get the max of the Series as a new Series of length 1.

Get the min of the Series as a new Series of length 1.

Get the mean of the Series as a new Series of length 1.

Get the median of the Series as a new Series of length 1.

Get the variance of the Series as a new Series of length 1.

Get the standard deviation of the Series as a new Series of length 1.

Get the quantile of the ChunkedArray as a new Series of length 1.

This is supported on crate feature temporal only.

Extract hour from underlying NaiveDateTime representation. Returns the hour number from 0 to 23.

This is supported on crate feature temporal only.

Extract minute from underlying NaiveDateTime representation. Returns the minute number from 0 to 59.

This is supported on crate feature temporal only.

Extract second from underlying NaiveDateTime representation. Returns the second number from 0 to 59.

This is supported on crate feature temporal only.

Returns the number of nanoseconds since the whole non-leap second. The range from 1,000,000,000 to 1,999,999,999 represents the leap second.

This is supported on crate feature temporal only.

Extract day from underlying NaiveDateTime representation. Returns the day of month starting from 1.

The return value ranges from 1 to 31. (The last day of month differs by months.)

This is supported on crate feature temporal only.

Returns the weekday number where monday = 0 and sunday = 6

This is supported on crate feature temporal only.

Returns the ISO week number starting from 1. The return value ranges from 1 to 53. (The last week of year differs by years.)

This is supported on crate feature temporal only.

Returns the day of year starting from 1.

The return value ranges from 1 to 366. (The last day of year differs by years.)

This is supported on crate feature temporal only.

Extract month from underlying NaiveDateTime representation. Returns the month number starting from 1.

The return value ranges from 1 to 12.

This is supported on crate feature temporal only.

Extract month from underlying NaiveDateTime representation. Returns the year number in the calendar date.

This is supported on crate feature temporal only.

Format Date/Datetimewith a fmt rule. See chrono strftime/strptime.

This is supported on crate feature temporal only.

Convert date(time) object to timestamp in ms.

Clone inner ChunkedArray and wrap in a new Arc

This is supported on crate feature object only.

Get the value at this index as a downcastable Any trait ref.

This is supported on crate feature object only.

Get a hold to self as Any trait reference. Only implemented for ObjectType

Raise a numeric series to the power of exponent.

Get a boolean mask of the local maximum peaks.

Get a boolean mask of the local minimum peaks.

This is supported on crate feature is_in only.

Check if elements of this Series are in the right Series, or List values of the right Series.

This is supported on crate feature repeat_by only.
This is supported on crate feature checked_arithmetic only.
This is supported on crate feature is_first only.

Get a mask of the first unique values.

This is supported on crate feature mode only.

Compute the most occurring element in the array.

This is supported on crate feature rolling_window only.

Apply a custom function over a rolling/ moving window of the array. This has quite some dynamic dispatch, so prefer rolling_min, max, mean, sum over this.

This is supported on crate feature concat_str only.

Concat the values into a string array.

Arguments
  • delimiter - A string that will act as delimiter between values.

Implementations

Trait Implementations

Performs the conversion.

Performs the conversion.

Performs the conversion.

Implementors