Git Product home page Git Product logo

Comments (1)

gforsyth avatar gforsyth commented on September 23, 2024

Hey @contang0 -- it has an effect, but the names column you've given it is already sorted (taking into account that we only need a set of column names.

[ins] In [1]: import ibis
         ...: import pandas as pd
         ...: 
         ...: ibis.options.interactive = True
         ...: 
         ...: con = ibis.duckdb.connect(":memory:")
         ...: 
         ...: data = pd.DataFrame(
         ...:     {
         ...:         "unique_id": ["A", "A", "B", "B"],
         ...:         "secondary_id": [
         ...:             "T2",
         ...:             "T2",
         ...:             "T1",
         ...:             "T1",
         ...:         ],
         ...:         "col1": ["x1", "x2", "x3", "x4"],
         ...:         "col2": ["y1", "y2", "y3", "y4"],
         ...:     }
         ...: )
         ...: 
         ...: tbl = ibis.memtable(data)

[ins] In [2]: tbl.pivot_wider(
         ...:     id_cols=["unique_id"],
         ...:     names_from=["secondary_id"],
         ...:     values_from=["col1", "col2"],
         ...:     names_sort=False,
         ...: )
Out[2]: 
┏━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
┃ unique_idcol1_T2col2_T2col1_T1col2_T1 ┃
┡━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
│ stringstringstringstringstring  │
├───────────┼─────────┼─────────┼─────────┼─────────┤
│ Ax1y1NULLNULL    │
│ BNULLNULLx3y3      │
└───────────┴─────────┴─────────┴─────────┴─────────┘

[ins] In [3]: tbl.pivot_wider(
         ...:     id_cols=["unique_id"],
         ...:     names_from=["secondary_id"],
         ...:     values_from=["col1", "col2"],
         ...:     names_sort=True,
         ...: )
Out[3]: 
┏━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━┓
┃ unique_idcol1_T1col2_T1col1_T2col2_T2 ┃
┡━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━┩
│ stringstringstringstringstring  │
├───────────┼─────────┼─────────┼─────────┼─────────┤
│ ANULLNULLx1y1      │
│ Bx3y3NULLNULL    │
└───────────┴─────────┴─────────┴─────────┴─────────┘

from ibis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.