[][src]Struct polars::series::Series

pub struct Series(pub Arc<dyn SeriesTrait>);

Series

The columnar data type for a DataFrame. The Series enum consists of typed ChunkedArray's. To quickly cast a Series to a ChunkedArray you can call the method with the name of the type:

let s: Series = [1, 2, 3].iter().collect();
// Quickly obtain the ChunkedArray wrapped by the Series.
let chunked_array = s.i32().unwrap();

Arithmetic

You can do standard arithmetic on series.

let s: Series = [1, 2, 3].iter().collect();
let out_add = &s + &s;
let out_sub = &s - &s;
let out_div = &s / &s;
let out_mul = &s * &s;

Or with series and numbers.

let s: Series = (1..3).collect();
let out_add_one = &s + 1;
let out_multiply = &s * 10;

// Could not overload left hand side operator.
let out_divide = 1.div(&s);
let out_add = 1.add(&s);
let out_subtract = 1.sub(&s);
let out_multiply = 1.mul(&s);

Comparison

You can obtain boolean mask by comparing series.

use itertools::Itertools;
let s = Series::new("dollars", &[1, 2, 3]);
let mask = s.eq(1);
let valid = [true, false, false].iter();
assert!(mask
    .into_iter()
    .map(|opt_bool| opt_bool.unwrap()) // option, because series can be null
    .zip(valid)
    .all(|(a, b)| a == *b))

See all the comparison operators in the CmpOps trait

Iterators

The Series variants contain differently typed ChunkedArray's. These structs can be turned into iterators, making it possible to use any function/ closure you want on a Series.

These iterators return an Option<T> because the values of a series may be null.

use polars::prelude::*;
let pi = 3.14;
let s = Series::new("angle", [2f32 * pi, pi, 1.5 * pi].as_ref());
let s_cos: Series = s.f32()
                    .expect("series was not an f32 dtype")
                    .into_iter()
                    .map(|opt_angle| opt_angle.map(|angle| angle.cos()))
                    .collect();

Creation

Series can be create from different data structures. Below we'll show a few ways we can create a Series object.

// Series van be created from Vec's, slices and arrays
Series::new("boolean series", &vec![true, false, true]);
Series::new("int series", &[1, 2, 3]);
// And can be nullable
Series::new("got nulls", &[Some(1), None, Some(2)]);

// Series can also be collected from iterators
let from_iter: Series = (0..10)
    .into_iter()
    .collect();

Implementations

impl Series[src]

pub fn rename(&mut self, name: &str) -> &mut Series[src]

Rename series.

pub fn append(&mut self, other: &Series) -> Result<&mut Self>[src]

Append a Series of the same type in place.

pub fn sort_in_place(&mut self, reverse: bool) -> &mut Self[src]

Sort in place.

pub fn as_single_ptr(&mut self) -> Result<usize>[src]

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

pub fn cast<N>(&self) -> Result<Self> where
    N: PolarsDataType
[src]

Cast to some primitive type.

pub fn sum<T>(&self) -> Option<T> where
    T: NumCast
[src]

Returns None if the array is empty or only contains null values.

let s = Series::new("days", [1, 2, 3].as_ref());
assert_eq!(s.sum(), Some(6));

pub fn min<T>(&self) -> Option<T> where
    T: NumCast
[src]

Returns the minimum value in the array, according to the natural order. Returns an option because the array is nullable.

let s = Series::new("days", [1, 2, 3].as_ref());
assert_eq!(s.min(), Some(1));

pub fn max<T>(&self) -> Option<T> where
    T: NumCast
[src]

Returns the maximum value in the array, according to the natural order. Returns an option because the array is nullable.

let s = Series::new("days", [1, 2, 3].as_ref());
assert_eq!(s.max(), Some(3));

pub fn mean<T>(&self) -> Option<T> where
    T: NumCast
[src]

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

impl Series[src]

pub fn series_equal(&self, other: &Series) -> bool[src]

Check if series are equal. Note that None == None evaluates to false

pub fn series_equal_missing(&self, other: &Series) -> bool[src]

Check if all values in series are equal where None == None evaluates to true.

Methods from Deref<Target = dyn SeriesTrait>

pub fn unpack<N: 'static>(&self) -> Result<&ChunkedArray<N>> where
    N: PolarsDataType
[src]

Trait Implementations

impl Add<&'_ Series> for &DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the + operator.

impl Add<&'_ Series> for DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the + operator.

impl Add<&'_ Series> for &Series[src]

type Output = Series

The resulting type after applying the + operator.

impl<T> Add<T> for &Series where
    T: Num + NumCast
[src]

type Output = Series

The resulting type after applying the + operator.

impl<T> Add<T> for Series where
    T: Num + NumCast
[src]

type Output = Self

The resulting type after applying the + operator.

impl<'a> AsRef<dyn SeriesTrait + 'a> for Series[src]

impl ChunkCompare<&'_ Series> for Series[src]

pub fn eq(&self, rhs: &Series) -> BooleanChunked[src]

Create a boolean mask by checking for equality.

pub fn neq(&self, rhs: &Series) -> BooleanChunked[src]

Create a boolean mask by checking for inequality.

pub fn gt(&self, rhs: &Series) -> BooleanChunked[src]

Create a boolean mask by checking if lhs > rhs.

pub fn gt_eq(&self, rhs: &Series) -> BooleanChunked[src]

Create a boolean mask by checking if lhs >= rhs.

pub fn lt(&self, rhs: &Series) -> BooleanChunked[src]

Create a boolean mask by checking if lhs < rhs.

pub fn lt_eq(&self, rhs: &Series) -> BooleanChunked[src]

Create a boolean mask by checking if lhs <= rhs.

impl ChunkCompare<&'_ str> for Series[src]

impl<Rhs> ChunkCompare<Rhs> for Series where
    Rhs: NumComp
[src]

impl ChunkFillNoneValue<&'_ Series> for ListChunked[src]

impl ChunkVar<Series> for ListChunked[src]

impl<T> ChunkVar<Series> for ObjectChunked<T>[src]

impl Clone for Series[src]

impl Debug for Series[src]

impl Default for Series[src]

impl Deref for Series[src]

type Target = dyn SeriesTrait

The resulting type after dereferencing.

impl Display for Series[src]

impl Div<&'_ Series> for &DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the / operator.

impl Div<&'_ Series> for DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the / operator.

impl Div<&'_ Series> for &Series[src]

type Output = Series

The resulting type after applying the / operator.

pub fn div(self, rhs: Self) -> Self::Output[src]

let s: Series = [1, 2, 3].iter().collect();
let out = &s / &s;

impl<T> Div<T> for &Series where
    T: Num + NumCast
[src]

type Output = Series

The resulting type after applying the / operator.

impl<T> Div<T> for Series where
    T: Num + NumCast
[src]

type Output = Self

The resulting type after applying the / operator.

impl<T> From<ChunkedArray<T>> for Series where
    T: PolarsDataType,
    ChunkedArray<T>: IntoSeries
[src]

impl<'a> FromIterator<&'a Series> for ListChunked[src]

impl<'a> FromIterator<&'a bool> for Series[src]

impl<'a> FromIterator<&'a f32> for Series[src]

impl<'a> FromIterator<&'a f64> for Series[src]

impl<'a> FromIterator<&'a i16> for Series[src]

impl<'a> FromIterator<&'a i32> for Series[src]

impl<'a> FromIterator<&'a i64> for Series[src]

impl<'a> FromIterator<&'a i8> for Series[src]

impl<'a> FromIterator<&'a str> for Series[src]

impl<'a> FromIterator<&'a u16> for Series[src]

impl<'a> FromIterator<&'a u32> for Series[src]

impl<'a> FromIterator<&'a u64> for Series[src]

impl<'a> FromIterator<&'a u8> for Series[src]

impl FromIterator<Option<bool>> for Series[src]

impl FromIterator<Option<f32>> for Series[src]

impl FromIterator<Option<f64>> for Series[src]

impl FromIterator<Option<i16>> for Series[src]

impl FromIterator<Option<i32>> for Series[src]

impl FromIterator<Option<i64>> for Series[src]

impl FromIterator<Option<i8>> for Series[src]

impl FromIterator<Option<u16>> for Series[src]

impl FromIterator<Option<u32>> for Series[src]

impl FromIterator<Option<u64>> for Series[src]

impl FromIterator<Option<u8>> for Series[src]

impl FromIterator<Series> for ListChunked[src]

impl FromIterator<Series> for DataFrame[src]

pub fn from_iter<T: IntoIterator<Item = Series>>(iter: T) -> Self[src]

Panics

Panics if Series have different lengths.

impl FromIterator<bool> for Series[src]

impl FromIterator<f32> for Series[src]

impl FromIterator<f64> for Series[src]

impl FromIterator<i16> for Series[src]

impl FromIterator<i32> for Series[src]

impl FromIterator<i64> for Series[src]

impl FromIterator<i8> for Series[src]

impl FromIterator<u16> for Series[src]

impl FromIterator<u32> for Series[src]

impl FromIterator<u64> for Series[src]

impl FromIterator<u8> for Series[src]

impl IntoSeries for Series[src]

impl Mul<&'_ Series> for &DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the * operator.

impl Mul<&'_ Series> for DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the * operator.

impl Mul<&'_ Series> for &Series[src]

type Output = Series

The resulting type after applying the * operator.

pub fn mul(self, rhs: Self) -> Self::Output[src]

let s: Series = [1, 2, 3].iter().collect();
let out = &s * &s;

impl<T> Mul<T> for &Series where
    T: Num + NumCast
[src]

type Output = Series

The resulting type after applying the * operator.

impl<T> Mul<T> for Series where
    T: Num + NumCast
[src]

type Output = Self

The resulting type after applying the * operator.

impl<'a, T: AsRef<[&'a str]>> NamedFrom<T, [&'a str]> for Series[src]

impl<'a, T: AsRef<[Option<&'a str>]>> NamedFrom<T, [Option<&'a str>]> for Series[src]

impl<T: AsRef<[Option<String>]>> NamedFrom<T, [Option<String>]> for Series[src]

impl<T: AsRef<[Option<bool>]>> NamedFrom<T, [Option<bool>]> for Series[src]

impl<T: AsRef<[Option<f32>]>> NamedFrom<T, [Option<f32>]> for Series[src]

impl<T: AsRef<[Option<f64>]>> NamedFrom<T, [Option<f64>]> for Series[src]

impl<T: AsRef<[Option<i16>]>> NamedFrom<T, [Option<i16>]> for Series[src]

impl<T: AsRef<[Option<i32>]>> NamedFrom<T, [Option<i32>]> for Series[src]

impl<T: AsRef<[Option<i64>]>> NamedFrom<T, [Option<i64>]> for Series[src]

impl<T: AsRef<[Option<i8>]>> NamedFrom<T, [Option<i8>]> for Series[src]

impl<T: AsRef<[Option<u16>]>> NamedFrom<T, [Option<u16>]> for Series[src]

impl<T: AsRef<[Option<u32>]>> NamedFrom<T, [Option<u32>]> for Series[src]

impl<T: AsRef<[Option<u64>]>> NamedFrom<T, [Option<u64>]> for Series[src]

impl<T: AsRef<[Option<u8>]>> NamedFrom<T, [Option<u8>]> for Series[src]

impl<T: AsRef<[String]>> NamedFrom<T, [String]> for Series[src]

impl<T: AsRef<[bool]>> NamedFrom<T, [bool]> for Series[src]

impl<T: AsRef<[f32]>> NamedFrom<T, [f32]> for Series[src]

impl<T: AsRef<[f64]>> NamedFrom<T, [f64]> for Series[src]

impl<T: AsRef<[i16]>> NamedFrom<T, [i16]> for Series[src]

impl<T: AsRef<[i32]>> NamedFrom<T, [i32]> for Series[src]

impl<T: AsRef<[i64]>> NamedFrom<T, [i64]> for Series[src]

impl<T: AsRef<[i8]>> NamedFrom<T, [i8]> for Series[src]

impl<T: AsRef<[u16]>> NamedFrom<T, [u16]> for Series[src]

impl<T: AsRef<[u32]>> NamedFrom<T, [u32]> for Series[src]

impl<T: AsRef<[u64]>> NamedFrom<T, [u64]> for Series[src]

impl<T: AsRef<[u8]>> NamedFrom<T, [u8]> for Series[src]

impl<T: AsRef<[Series]>> NamedFrom<T, ListType> for Series[src]

impl Rem<&'_ Series> for &DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the % operator.

impl Rem<&'_ Series> for DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the % operator.

impl Rem<&'_ Series> for &Series[src]

type Output = Series

The resulting type after applying the % operator.

pub fn rem(self, rhs: Self) -> Self::Output[src]

let s: Series = [1, 2, 3].iter().collect();
let out = &s / &s;

impl Sub<&'_ Series> for &DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the - operator.

impl Sub<&'_ Series> for DataFrame[src]

type Output = Result<DataFrame>

The resulting type after applying the - operator.

impl Sub<&'_ Series> for &Series[src]

type Output = Series

The resulting type after applying the - operator.

impl<T> Sub<T> for &Series where
    T: Num + NumCast
[src]

type Output = Series

The resulting type after applying the - operator.

impl<T> Sub<T> for Series where
    T: Num + NumCast
[src]

type Output = Self

The resulting type after applying the - operator.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> Cast<U> for T where
    U: FromCast<T>, 

impl<T> From<T> for T[src]

impl<T> FromCast<T> for T

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> ToCell for T where
    T: ToString
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,