Search code examples
pythonibis

Mutate a column in Ibis when column name has spaces


Given a dataframe that has a column with a space:

ibis.memtable({
    'colname with space': ['a', 'b', 'c']
})

I want to mutate this column. How do I reference it in the .mutate method? One way is table['colname with space'], however I consider this at best a workaround that doesn't work with anonymous tables.


Solution

  • In short, underscore with brakets.

    import ibis
    from ibis import _
    
    ibis.memtable(
        {'colname with space': ['a', 'b', 'c']}
        )\
        .mutate(new_col = _['colname with space'].upper())