Last active
December 29, 2022 21:41
-
-
Save ajkerrigan/bd9cb288d94ab3c080465691f9b0fd52 to your computer and use it in GitHub Desktop.
Hanukkah of Data 2022 - VisiData Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!vd -p | |
{"longname": "open-file", "input": "noahs-customers.csv", "keystrokes": "o"} | |
{"sheet": "noahs-customers", "col": "name", "row": "", "longname": "phone-keys-for-col", "input": "", "comment": ""} | |
{"sheet": "noahs-customers", "col": "", "row": "", "longname": "select-expr", "input": "phone.replace('-','') in name_phonekeys", "keystrokes": "z|", "comment": "select rows matching Python expression in any visible column"} | |
{"sheet": "noahs-customers", "col": "", "row": "", "longname": "dup-selected", "input": "", "keystrokes": "\"", "comment": "open duplicate sheet with only selected rows"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from visidata import vd, TableSheet, ExprColumn | |
phone_pad = { | |
"abc": 2, | |
"def": 3, | |
"ghi": 4, | |
"jkl": 5, | |
"mno": 6, | |
"pqrs": 7, | |
"tuv": 8, | |
"wxyz": 9, | |
} | |
vd.phone_lookup = str.maketrans( | |
{letter: str(number) for letters, number in phone_pad.items() for letter in letters} | |
) | |
@TableSheet.api | |
def phoneKeysFor(sheet, col): | |
newcol = ExprColumn("curcol.lower().replace(' ','').translate(vd.phone_lookup)", curcol=col) | |
newcol.name = f"{col.name}_phonekeys" | |
sheet.addColumnAtCursor(newcol) | |
TableSheet.addCommand("", "phone-keys-for-col", "sheet.phoneKeysFor(cursorCol)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment