Skip to content

Table commands - complete list #903

Closed as not planned
Closed as not planned

Description

@sophiajt

Here's an effort to "tile the space" to look for gaps in our current ability to work with tables.

Working with columns

Capability Nu Support
Filter to subset of columns select
Filter to a column by number MISSING
Filter to range of columns MISSING
Work with cell contents by column name get
Reorder columns move
Sort by column name(s) sort-by
Remove a column reject
Rename a column rename
Edit the contents of a column edit
Add a new column insert
Use row data to create new columns group-by
Create a column with the existing data embed
Filter columns based on condition MISSING

Working with rows

Capability Nu Support
Prepend a row prepend
Append a row append
Add a row at location MISSING
Replace a row MISSING
Remove a row nth --skip
Retrieve a given row nth
Retrieve a set of rows nth <set of rows>
Retrieve a range of rows range
Retrieve a range of rows from front first
Retrieve a range of rows from end last
Filter rows based on condition where

Whole table

Capability Nu Support
Turning rows <-> columns pivot
Reverse the rows of a table reverse
Count size of table in rows count
Count size of table in columns count --column

Literals

Capability Nu Support
Write a row literal []
Write a table literal []

Converting strings to tables

Capability Nu Support
Create column data from strings read, split column
Create row data from strings split row
Load known structure from string from *
Load structure from tagged string MISSING

Activity

  1. added
    category:meta-issue
    on Apr 18, 2020
  2. github-actions commented on Jun 24, 2021

    @github-actions

    This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

  3. waldyrious commented on Jul 4, 2021

    @waldyrious
    Contributor

    This definitely doesn't look like an issue that should be closed for lack of updates. (Just commenting in case stale-bot is about to close it.)

  4. github-actions commented on Oct 6, 2021

    @github-actions

    This issue is being marked stale because it has been open for 90 days without activity. If you feel that this is in error, please comment below and we will keep it marked as active.

  5. hustcer commented on Oct 6, 2021

    @hustcer
    Contributor

    No stale

  6. fdncred commented on Feb 18, 2022

    @fdncred
    Contributor

    @jntrnr this looks good for some documentation after it's updated for 0.59. :)

  7. sophiajt commented on Aug 9, 2023

    @sophiajt
    ContributorAuthor

    Keeping this open as the missing ones are still missing. It would be great to fix these for 1.0.

  8. cbr9 commented on Sep 30, 2023

    @cbr9

    How about creating an empty table? Is this possible?

  9. fdncred commented on Sep 30, 2023

    @fdncred
    Contributor

    How about creating an empty table? Is this possible?

    I don't understand the use case. What's the point of an empty table?

  10. cbr9 commented on Sep 30, 2023

    @cbr9

    How about creating an empty table? Is this possible?

    I don't understand the use case. What's the point of an empty table?

    Actually, I was juggling with a problem but I found the solution without the need for empty tables (still trying to learn nushell)

  11. added a commit that references this issue on Oct 22, 2023
  12. stellarpower commented on Oct 28, 2023

    @stellarpower

    How about creating an empty table? Is this possible?

    I was in the same situation. If you're not used to working functionally most of the time, this is a sensible starting place. Then you mutate it by adding in your column headers, and then add in values.

  13. stellarpower commented on Oct 28, 2023

    @stellarpower

    Here's an effort to "tile the space" to look for gaps in our current ability to work with tables.

    Working with columns

    Capability Nu Support
    Filter to subset of columns select
    Filter to a column by number MISSING
    ...
    ...

    Could a roundup like this be added to the documentation? This is really nice as a rapid index of what command I need to look for for a given job - more so than the more detailed pages here or here say, and this reads better to me (what I want to do is on the left; the command I need is on the right, and there may be a many-1 relationship between what I want and the command) than e.g. the listings of subcommands for strings here - not that the latter isn't useful as a reference in its own right. But this is excellent for trying to find what I need to type in when I don't know the name but I know what I need to do. Some indentation into a tree perhaps would then allow grouping related things I need to do (e.g. the retrieve a row ... can be grouped together)

  14. fdncred commented on Oct 28, 2023

    @fdncred
    Contributor

    Here's one way to create a table in a mutable fashion.

    mut table = [] # A table is a list of records. So, let's start with an empty list.
    let rec1 = {col:1} # A simple record with col as the key and 1 as the value
    let rec2 = {col:2} # Another record, note the same key
    $table # it's currently empty
    $table = ($table | append $rec1 | append $rec2) # take $table and assign it $table while appending the 2 records
    $table
    ╭#┬col╮
    │0│  1│
    │1│  2│
    ╰─┴───╯
  15. stellarpower commented on Oct 28, 2023

    @stellarpower

    Okay, so just an empty list. Thanks. I assumed it would be something like that, but wasn't sure. At that point I stepped back and realised I could probably do it with a map instead.

    I also wasn't aware it was possible to use a "bare" assignment like that - I have done $record.field = value before, but possibly not $record = value. Would using let table = (...) then introduce an immutable variable that shadows the original one, same as it does normally?

  16. fdncred commented on Oct 29, 2023

    @fdncred
    Contributor

    let disallows mutability. You'd have to do mut table

  17. stellarpower commented on Oct 29, 2023

    @stellarpower
    ~> mut hello = "world"                                                            
    ~> let hello = "WORLD"   

    Right, but what I mean is that here, this is shadowing the original variable right? Whereas using an equals sign is just mutating it.

  18. fdncred commented on Oct 29, 2023

    @fdncred
    Contributor

    yes, that's shadowing.

  19. Zoybean commented on Jan 22, 2024

    @Zoybean
    Contributor

    It seems like the tables at the top of this post are out of date. There's a few commands that have either been renamed or removed, and I'm not sure of all of them.

    Working with columns

    Capability old new
    Edit the contents of a column edit update?
    Create a column with the existing data embed ?

    Working with rows

    Capability old new
    Remove a row nth --skip drop nth
    Retrieve a given row nth ?
    Retrieve a set of rows nth <set of rows> ?

    Whole table

    Capability old new
    Turning rows <-> columns pivot transpose
    Count size of table in rows count length
    Count size of table in columns count --column ?

    Converting strings to tables

    Capability old new
    Create column data from strings read, split column parse?, split column
  20. NotTheDr01ds commented on Sep 1, 2024

    @NotTheDr01ds
    Contributor

    Some of the "Missing" items can now be done easily enough that I don't know that there's a need for a dedicated command.

    Filtering to a column by number

    let column_name = 2
    ls | select ($in | columns | get $column_number)

    Filtering to a range of columns

    let start_range = 0
    let end_range = 2
    ls | select ...($in | columns | range ($start_range)..($end_range))

    Filtering by column conditions

    Not 100% sure what is meant there, but I think a transpose would work?


    Add a row at location

    Can be done with spreading:

    let insert_at = 4
    ls |
      [
        ...($in | range 0..($insert_at))
        { name: foo, size: 0b }
        ...($in | range ($insert_at + 1)..)
      ]

    Replace a row

    update handles this:

    ls | update 4 { name: foo }
  21. fdncred commented on Sep 1, 2024

    @fdncred
    Contributor

    Agreed that the OP could be updated. But I also like seeing things like "here are the table commands", "here are the record commands", "here are the list commands", etc.

  22. youk commented on Aug 27, 2025

    @youk

    I don't understand the use case. What's the point of an empty table?

    To have a sort of option type so that data can be handled in a uniform way? Let's say there are no records and I still want to output table header (and possibly some indication that the table is empty):

    $ [[name age]; [Sid 17]] | drop 1
    
    #   name   age
    ────────────────
    

    Not possible, since the table without records effectively becomes a list. The solution I came up with looks clumsy:

    mut table = [[name age]; [Sid 17]]
    let header = ($table | table | lines | drop ($table | length) | to text)
    $table = $table | drop 1
    if ($table | is-empty) {
        print -n $header
        print $'(ansi d)empty table(ansi reset)'
    } else {
        $table
    }
    

    Now let's move on to something more prosaic:

    mut table = []
    $table.invalid_column_name
    
    ╭────────────╮
    │ empty list │
    ╰────────────╯
    
    $table = $table | append {a:1}
    $table.invalid_column_name
    
    cannot find column 'invalid_column_name'
    

    This is not what sane programming is about.

  23. kronberger-droid commented on Nov 13, 2026

    @kronberger-droid
    Contributor

    This list is from 2019 and doesn't match the current command set anymore (edit, embed, nth, pivot and count are gone or renamed).
    As shown above most of the rows marked as missing are one-liners by now.
    So i think it doesn't track a gap anymore and i'm closing it.
    The discussion about empty tables continues in #19320.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:meta-issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions