BurntSushi / xsv

A fast CSV command line toolkit written in Rust.
The Unlicense
10.29k stars 317 forks source link

Accessing columns with numeric names #253

Open kotwys opened 3 years ago

kotwys commented 3 years ago

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.)

BurntSushi commented 3 years ago

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.

kotwys commented 3 years ago

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

BurntSushi commented 3 years ago

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?

kotwys commented 3 years ago

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.