Code Monkey home page Code Monkey logo

Comments (3)

deculler avatar deculler commented on July 25, 2024

We removed this operation from the class because it is pretty easy to get
with numpy.unique. You need to ask it for both unique values and the map.
Absolutely important so we should have the example.
On Sep 14, 2015 3:06 PM, "davidwagner" [email protected] wrote:

Goal: Given a table T and a column C, build a new table that has one row
for each unique value in T.C along with a count of the number of times that
value appears in T.C.

I was not able to find any clean way to do this within the Table API.
Should this be doable using Tables, without leaving Table space and going
back to arrays and raw Python?

Here is the solution I came up with:

from collections import Counter
c = Counter(origtbl['column_label'])
t = Table.from_rows(c.items(), ['column_label', 'count'])

Not so terrible if you know Python idioms, but also probably not so
discoverable for students. Should there be an API in Table that's
accessible to students that allows performing this kind of task? Or some
suitable generalized primitive, which is enough to solve this problem?


Reply to this email directly or view it on GitHub
#68.

from datascience.

davidwagner avatar davidwagner commented on July 25, 2024

Cool. Thank you. Note to future self: np.unique(x, return_counts=True)

from datascience.

deculler avatar deculler commented on July 25, 2024

Here's the example

T = Table([['A','A','B','C','A']],['letters'])
labels, counts = np.unique(T['letters'],return_counts=True)
R = Table(list(counts),list(labels))

from datascience.

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.