Home > database >  How to format the layout of a CSV or JSON file
How to format the layout of a CSV or JSON file

Time:09-23

I need to format the layout of a CSV or JSON-file.

So I'm working on a project, where the user is able to do messurements. The results are written into a mysql database. There is a button so you can convert the database into csv-format and download it.

The table looks like this

You can see three columns named (register, pressure and timestamp). What I want to do is to format the layout so if the user downloads the data he gets another representation of the table. The value of the timestamp shouldnt be multiple times in the table.

It's hard to explain so I created a table of how I want it to look like right here

CodePudding user response:

You should add real data, not only images.

Here an example, similar to your input structure:

Register Druck Zeitstempel
1 3 a
2 5 a
3 45 a
1 9 b
2 12 b

The raw data

Register,Druck,Zeitstempel
1,3,a
2,5,a
3,45,a
1,9,b
2,12,b

Using Miller and running

mlr --csv reshape -s Zeitstempel,Druck then unsparsify input.csv

You will have in output

Register a b
1 3 9
2 5 12
3 45
  • Related