VisiData Lightning Demo at PyCascades 2018
$ pip3 install visidata openpyxl
$ vd data.csv
python >= 3.6
Data 파일을 column으로 나누어 보기 쉽게 해주는 툴이다.
불러들인 데이터에서 plot도 가능하다.
엑셀파일(xlsx)도 읽기가 가능하다. 그러기 위해서는 openpyxl을 설치해야 한다.
Usage:
- Data type: # (int), % (float), $ (currency), or @ (date)
- Select column: !
- Sort: [ ] (ascending/descending by current column)
- Graph: .
- Hide column: - (dash)
- Conditional select: z|
- Row: s (select) t (toggle) u (unselected) gd (delete selected rows)
- Delete row: d
- Move column position: Shift-h (left) or Shift-l (right)
- Edit cell value: e https://www.visidata.org/docs/edit/
Creating new columns
za | Create a blank column |
i | Create an increment column (1,2,3…) |
= + expr | expr Create a new column from a Python expr evaluated against each row |
: + regex | regex Create new column(s) by splitting current column on regex |
; + regex | regex Create new column(s) by extracting regex groups from current column |
' | Create "frozen" copy of current column, with all cells evaluated |
4.1.2. Regular expression metacharacters
A regular expression may be followed by one of several repetition operators (metacharacters):
Table 4-1. Regular expression operators
OperatorEffect. | Matches any single character. |
? | The preceding item is optional and will be matched, at most, once. |
* | The preceding item will be matched zero or more times. |
+ | The preceding item will be matched one or more times. |
{N} | The preceding item is matched exactly N times. |
{N,} | The preceding item is matched N or more times. |
{N,M} | The preceding item is matched at least N times, but not more than M times. |
- | represents the range if it's not first or last in a list or the ending point of a range in a list. |
^ | Matches the empty string at the beginning of a line; also represents the characters not in the range of a list. |
$ | Matches the empty string at the end of a line. |
\b | Matches the empty string at the edge of a word. |
\B | Matches the empty string provided it's not at the edge of a word. |
\< | Match the empty string at the beginning of word. |
\> | Match the empty string at the end of word. |
Two regular expressions may be concatenated; the resulting regular expression matches any string formed by concatenating two substrings that respectively match the concatenated subexpressions.
Two regular expressions may be joined by the infix operator "|"; the resulting regular expression matches any string matching either subexpression.
Repetition takes precedence over concatenation, which in turn takes precedence over alternation. A whole subexpression may be enclosed in parentheses to override these precedence rules.
4.1.3. Basic versus extended regular expressions
In basic regular expressions the metacharacters "?", "+", "{", "|", "(", and ")" lose their special meaning; instead use the backslashed versions "\?", "\+", "\{", "\|", "\(", and "\)".
Check in your system documentation whether commands using regular expressions support extended expressions.
Matching Numeric Ranges with a Regular Expression
Since regular expressions deal with text rather than with numbers, matching a number in a given range takes a little extra care. You can’t just write [0-255] to match a number between 0 and 255. Though a valid regex, it matches something entirely different. [0-255] is a character class with three elements: the character range 0-2, the character 5 and the character 5 (again). This character class matches a single digit 0, 1, 2 or 5, just like [0125].
Since regular expressions work with text, a regular expression engine treats 0 as a single character, and 255 as three characters. To match all characters from 0 to 255, we’ll need a regex that matches between one and three characters.
The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. That’s the easy part.
Matching the three-digit numbers is a little more complicated, since we need to exclude numbers 256 through 999. 1[0-9][0-9] takes care of 100 to 199. 2[0-4][0-9] matches 200 through 249. Finally, 25[0-5] adds 250 till 255.
As you can see, you need to split up the numeric range in ranges with the same number of digits, and each of those ranges that allow the same variation for each digit. In the 3-digit range in our example, numbers starting with 1 allow all 10 digits for the following two digits, while numbers starting with 2 restrict the digits that are allowed to follow.
Putting this all together using alternation we get: [0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]. This matches the numbers we want, with one caveat: regular expression searches usually allow partial matches, so our regex would match 123 in 12345. There are two solutions to this.
Searching for Numeric Ranges
If you’re searching for these numbers in a larger document or input string, use word boundaries to require a non-word character (or no character at all) to precede and to follow any valid match. The regex then becomes \b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b. Since the alternation operator has the lowest precedence of all, the parentheses are required to group the alternatives together. This way the regex engine will try to match the first word boundary, then try all the alternatives, and then try to match the second word boundary after the numbers it matched. Regular expression engines consider all alphanumeric characters, as well as the underscore, as word characters.
Validating Numeric Ranges
If you’re using the regular expression to validate input, you’ll probably want to check that the entire input consists of a valid number. To do this, replace the word boundaries with anchors to match the start and end of the string: ^([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$.
Here are a few more common ranges that you may want to match:
- 000..255: ^([01][0-9][0-9]|2[0-4][0-9]|25[0-5])$
- 0 or 000..255: ^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$
- 0 or 000..127: ^(0?[0-9]?[0-9]|1[01][0-9]|12[0-7])$
- 0..999: ^([0-9]|[1-9][0-9]|[1-9][0-9][0-9])$
- 000..999: ^[0-9]{3}$
- 0 or 000..999: ^[0-9]{1,3}$
- 1..999: ^([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$
- 001..999: ^(00[1-9]|0[1-9][0-9]|[1-9][0-9][0-9])$
- 1 or 001..999: ^(0{0,2}[1-9]|0?[1-9][0-9]|[1-9][0-9][0-9])$
- 0 or 00..59: ^[0-5]?[0-9]$
- 0 or 000..366: ^([012]?[0-9]?[0-9]|3[0-5][0-9]|36[0-6])$
https://jsvine.github.io/visidata-cheat-sheet/en/
https://www.regular-expressions.info/numericranges.html
https://realpython.com/regex-python/
Github : https://github.com/saulpw/visidata
사용법 : https://www.visidata.org/docs/
'Tools' 카테고리의 다른 글
DeepVariant (0) | 2021.01.18 |
---|---|
docker (0) | 2021.01.18 |
Find connection (0) | 2020.11.04 |
Jobs for you (0) | 2020.10.22 |
tmux-cssh (0) | 2020.10.22 |
댓글