xsv icon indicating copy to clipboard operation
xsv copied to clipboard

Accessing columns with numeric names

Open kotwys opened this issue 5 years ago • 4 comments

Hello! Sorry if it's irrelevant, but I think there's an issue.

If you have a table having numeric-named columns, you can't select them by just writing

xsv select '2020' # supposing that there's no 2020 columns

The program thinks this is the column's ordinal number and obviously can't find it in the case above. You can actually access it by its number among the others or by writing 2015[0] instead but in my mind there should be some more intuitive way of doing this (or that should be added to the help pages.)

kotwys avatar Dec 14 '20 18:12 kotwys

Could you please provide sample inputs along with commands and the desired output? I think I understand what you're asking for here, but I'm not 100% clear. In general, whenever possible, please include sample inputs/outputs when filing issues.

BurntSushi avatar Dec 14 '20 19:12 BurntSushi

Oh sorry if I didn't make it clear. Taking this as an example:

Country Name, 2019, 2020
A, 3821, 3211
B, 4382, 4212

I'd try using something like this

xsv select '"Country Name","2019"' # maybe some other syntax

to get

Country Name, 2019
A, 3821
B, 4382

But actually the program says:

Selector index 2019 is out of bounds. Index must be >= 1 and <= 3.

The problem can be workarounded by selecting columns 2 or 2019[0] but I think there could be a better way

kotwys avatar Dec 14 '20 19:12 kotwys

Ah I see, thank you. I was confused because you had 2020 and then used 2015[0] later.

but I think there could be a better way

Can you suggest one?

BurntSushi avatar Dec 14 '20 19:12 BurntSushi

I think that everything surrounded by quotes should be treated as a string. Don't actually know whether one would and does use indices explicitly enclosed in quote marks or not.

kotwys avatar Dec 15 '20 12:12 kotwys