Giter VIP home page Giter VIP logo

Comments (5)

saulpw avatar saulpw commented on May 24, 2024 1

Change c to self.

I just kind of tossed this code off, I thought maybe you knew how to code in Python a bit and could fix the issues and get it working for yourself. Adding this feature properly will probably require more polish (including documentation and a test) once it's working, and it's not a priority on our roadmap.

Kondo'ed for now.

from visidata.

saulpw avatar saulpw commented on May 24, 2024

What is the error in one of the cells? You can see it with z Ctrl+E.

from visidata.

maxim-uvarov avatar maxim-uvarov commented on May 24, 2024
Traceback (most recent call last):
File "/Users/user/miniconda3/lib/python3.11/site-packages/visidata/wrappers.py", line 105, in wrapply
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/miniconda3/lib/python3.11/site-packages/visidata/column.py", line 340, in getValue
return self.calcValue(row)
^^^^^^^^^^^^^^^^^^^
File "/Users/user/.visidatarc", line 27, in calcValue
prevval = self.prevCol.getTypedValue(row)
^^^^^^^^^^^^
AttributeError: 'DiffPreviousColumn' object has no attribute 'prevCol'

from visidata.

saulpw avatar saulpw commented on May 24, 2024

Change prevCol to sourceCol (or vice versa).

from visidata.

maxim-uvarov avatar maxim-uvarov commented on May 24, 2024

I changed the code and now I got this error:

Traceback (most recent call last):
File "/Users/user/miniconda3/lib/python3.11/site-packages/visidata/wrappers.py", line 105, in wrapply
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/miniconda3/lib/python3.11/site-packages/visidata/column.py", line 340, in getValue
return self.calcValue(row)
^^^^^^^^^^^^^^^^^^^
File "/Users/user/.visidatarc", line 28, in calcValue
curval = c.getTypedValue(row)
^
NameError: name 'c' is not defined

my current code is:

class DiffPreviousColumn(Column):
    def calcValue(self, row):
        prevval = self.sourceCol.getTypedValue(row)
        curval = c.getTypedValue(row)
        #return (curval-prevval)/prevval
        return 1

@Sheet.api
def diff_cols(sheet):
    for c in vd.numericCols(sheet.visibleCols):
        newcol = DiffPreviousColumn(c.name + 'diff', type=float, sourceCol=c)
        sheet.addColumn(newcol, index=sheet.columns.index(c))
        c.hide()

Sheet.addCommand('', 'diff-cols', 'diff_cols()')

from visidata.

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.