-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to do a simple transposed view of csv ? #321
Comments
Starting from this input
and running
I have this
Is not what you want? If no, could you insert an example input and an example output? |
Thanks for answering. I need a simple rotate left /transpose for example , Input csv is 4 column and 5 rows, with h1..4 being headers h1 ,h2, h3, h4 Output is just like I rotated it left 90 degree. h1 r1v1 r2v1 r3v1 r4v1 r5v1 This is very useful when seeing changes in v1 over all the very small number of rows in dataset because when the number of columns or headers is in hundreds the overlapped pretty print is hard to make sense of. Maybe if there's a verb called rotate or transpose that would be very useful. |
@ashmishr nice! At present what I have is the XTAB output format as you noted ... Decades ago I wrote this: https://github.com/johnkerl/scripts/blob/master/fundam/xpose
where https://github.com/johnkerl/scripts/blob/master/fundam/left is nice in case the cell values aren't all the same length (even though they are in this example). |
@johnkerl thanks. you forced me to write a one liner that I was resisting 👍
Or couple of lines in my shell profile so its invocable as a command from sqsh etc.
But I hope you would please consider making it a native feature :) |
There is a cli to do that: https://bioinf.shenwei.me/csvtk/usage/#transpose |
Thanks @ashmishr! Regarding native feature ... I'm not sure this makes sense in Miller which is (uniquely) keyed by field name ... |
See also #688 |
Closing as dup of #688 -- please re-open if I'm mistaken -- thanks! :) |
Here's a simple way to transpose a CSV with Miller: mlr --csv -N put -q '
for (k,v in $*) { @arr[k][NR] = v }
end { emit @arr }
' file.csv |
You are great @Fravadona and I would need to learn to use dsl better. I am truly a goat |
there is also datamash $ echo "1 2 3 4 5"|datamash --field-separator ' ' transpose |
Actually, there are some cases we need to transpose the data file to be row-based csv, because it is origianlly a vertical csv which arrange time series data vertically. The headers are placed vertically in the first column. This means a transpose is a must before Miller do other processing. So absolutely agree with @ashmishr that transpose should be a native verb. |
I often have to query time series data-warehouses with over 500 columns . I tried xtab and reshape but cannot get a simple transform of just rotating my laptop by 90 degree.
Generally the time range is a week and we need to see all the values side by side to observe how its changing, so json etc is not right. Any help is appreciated.
The text was updated successfully, but these errors were encountered: