Skip to content

Commit

Permalink
[Rust][Documentation] New example for DataFrame::iter (#1852)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibENPC committed Nov 21, 2021
1 parent 0c11e73 commit 5ee01df
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions polars/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,25 @@ impl DataFrame {
}

/// Iterator over the columns as Series.
///
/// # Example
///
/// ```rust
/// use polars_core::prelude::*; // or "use polars::prelude::*"
///
/// fn example() -> Result<()> {
/// let s1: Series = Series::new("Name", &["Pythagoras' theorem", "Shannon entropy"]);
/// let s2: Series = Series::new("Formula", &["a²+b²=c²", "H=-Σ[P(x)log|P(x)|]"]);
/// let df: DataFrame = DataFrame::new(vec![s1.clone(), s2.clone()])?;
///
/// let mut iterator = df.iter();
/// assert_eq!(iterator.next(), Some(&s1));
/// assert_eq!(iterator.next(), Some(&s2));
/// assert_eq!(iterator.next(), None);
///
/// Ok(())
/// }
/// ```
pub fn iter(&self) -> std::slice::Iter<'_, Series> {
self.columns.iter()
}
Expand Down

0 comments on commit 5ee01df

Please sign in to comment.