Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Deprecated
    • Env
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

polars into-df for dataframe

Converts a list, table or record into a dataframe.

This command requires a plugin

The polars into-df command resides in the polars plugin. To use this command, you must install and register nu_plugin_polars. See the Plugins chapter in the book for more information.

Signature

> polars into-df {flags}

Flags

  • --schema, -s {record}: Polars Schema in format [{name: str}]. CSV, JSON, and JSONL files
  • --as-columns, -c: When input shape is record of lists, treat each list as column values.

Input/output types:

inputoutput
anyany

Examples

Takes a dictionary and creates a dataframe

> [[a b];[1 2] [3 4]] | polars into-df
╭───┬───┬───╮
│ # │ a │ b │
├───┼───┼───┤
│ 0 │ 1 │ 2 │
│ 1 │ 3 │ 4 │
╰───┴───┴───╯

Takes a record of lists and creates a dataframe

> {a: [1 3], b: [2 4]} | polars into-df --as-columns
╭───┬───┬───╮
│ # │ a │ b │
├───┼───┼───┤
│ 0 │ 1 │ 2 │
│ 1 │ 3 │ 4 │
╰───┴───┴───╯

Takes a list of tables and creates a dataframe

> [[1 2 a] [3 4 b] [5 6 c]] | polars into-df
╭───┬───┬───┬───╮
│ # │ 0 │ 1 │ 2 │
├───┼───┼───┼───┤
│ 0 │ 1 │ 2 │ a │
│ 1 │ 3 │ 4 │ b │
│ 2 │ 5 │ 6 │ c │
╰───┴───┴───┴───╯

Takes a list and creates a dataframe

> [a b c] | polars into-df
╭───┬───╮
│ # │ 0 │
├───┼───┤
│ 0 │ a │
│ 1 │ b │
│ 2 │ c │
╰───┴───╯

Takes a list of booleans and creates a dataframe

> [true true false] | polars into-df
╭───┬───────╮
│ # │   0   │
├───┼───────┤
│ 0 │ true  │
│ 1 │ true  │
│ 2 │ false │
╰───┴───────╯

Convert to a dataframe and provide a schema

> [[a b c]; [1 {d: [1 2 3]} [10 11 12] ]]| polars into-df -s {a: u8, b: {d: list<u64>}, c: list<u8>}
╭───┬───┬───────────────────┬────────────╮
│ # │ a │         b         │     c      │
├───┼───┼───────────────────┼────────────┤
│ 0 │ 1 │ ╭───┬───────────╮ │ ╭───┬────╮ │
│   │   │ │   │ ╭───┬───╮ │ │ │ 0 │ 10 │ │
│   │   │ │ a │ │ 0 │ 1 │ │ │ │ 1 │ 11 │ │
│   │   │ │   │ │ 1 │ 2 │ │ │ │ 2 │ 12 │ │
│   │   │ │   │ │ 2 │ 3 │ │ │ ╰───┴────╯ │
│   │   │ │   │ ╰───┴───╯ │ │            │
│   │   │ ╰───┴───────────╯ │            │
╰───┴───┴───────────────────┴────────────╯

Convert to a dataframe and provide a schema that adds a new column

> [[a b]; [1 "foo"] [2 "bar"]] | polars into-df -s {a: u8, b:str, c:i64} | polars fill-null 3
╭───┬───┬─────┬───╮
│ # │ a │  b  │ c │
├───┼───┼─────┼───┤
│ 0 │ 1 │ foo │ 3 │
│ 1 │ 2 │ bar │ 3 │
╰───┴───┴─────┴───╯
Edit this page on GitHub
Contributors: JT, hustcer, Reilly Wood, Justin Ma, Leon, Hofer-Julian, Texas Toland, sholderbach