[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Table filter.
From: |
Nick Dokos |
Subject: |
Re: [O] Table filter. |
Date: |
Tue, 08 May 2012 11:10:37 -0400 |
Bastien <address@hidden> wrote:
> Hi Petro,
>
> Petro <address@hidden> writes:
>
> > lets say I have a table
> >
> > | n | 2 | 3 | 4 | 5 | 6 |
> > |---+---+---+---+---+---|
> > | 1 | a | | | | |
> > | 2 | b | | | | |
> > | 3 | b | | | | |
> > | 4 | a | | | | |
> > | 5 | c | | | | |
> > | 6 | b | | | | |
> > | 7 | a | | | | |
> >
> > I want to filter this table and get only rows where second column equal a
> > | n | 2 | 3 | 4 | 5 | 6 |
> > |---+---+---+---+---+---|
> > | 1 | a | | | | |
> > | 4 | a | | | | |
> > | 7 | a | | | | |
>
> Such feature does not exist for now, but I would welcome enhancements in
> this direction. Thanks for this idea,
>
You can get most of the way there with babel, as long as you don't insist
on modifying the table in place. Something like this e.g. using python 2.x:
--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC elisp
(setq org-babel-min-lines-for-block-output 0)
#+END_SRC
#+RESULTS:
#+begin_example
0
#+end_example
The above setting is just to force an example block. The default value
(10) produces colon-demarcated results.
#+name: orig
| n | 2 | 3 | 4 | 5 | 6 |
|---+---+---+---+---+---|
| 1 | a | | | | |
| 2 | b | | | | |
| 3 | b | | | | |
| 4 | a | | | | |
| 5 | c | | | | |
| 6 | b | | | | |
| 7 | a | | | | |
#+BEGIN_SRC python :var table=orig :results output
# print the header
print "#+name: filtered"
for x in table:
if x[1] == 'a':
print "|%s" % ("|".join(map(str, x)))
#+END_SRC
#+RESULTS:
#+begin_example
#+name: filtered
|1|a||||
|4|a||||
|7|a||||
#+end_example
--8<---------------cut here---------------end--------------->8---
I don't know how to get the column heading row though: apparently babel
strips it from the table it passes to the code block.
Nick