Question

Extract values from a column

  • 24 March 2020
  • 2 replies
  • 3 views

Badge +1

I know there are already posts about this, but couldn't find much info about it.

I have a column in csv with multiple fields and values in the same column:

col1

 

{ "21" : 80.0, "81" : null, "21" : 100.0, "21" : 60.0 }

 

{ "21" : 60.0, "21" : 80.0, "81" : null, "21" : 80.0, "21" : 100.0, "21" : 100.0, "21" : 60.0 }

 

 

Representation-

21- max speed

81- max weight

The occurrence of fields:1st time- Car, 2nd time- Bus, 3rd time-Truck

Max Speed (Car)

 

Max Weight(Car)

 

Max Speed (Bus)

 

Max Speed (Truck)

 

Max Speed(D Truck)

 

Max Speed (B Truck)

 

80

 

null

 

100

 

60

 

null

 

null

 

60

 

null

 

80

 

100

 

100

 

100

 

 

Attaching the csv.

I am able to use AttribuleSplitter, SubstringExtractor and putting them in fields, but the values are not in uniformity. Any suggestions?

Thanks in advance.


2 replies

Userlevel 1
Badge +21

If I've understood correctly, i would use a string searcher with some regex to pull into a list all the speed elements and simply rename these, then repeat with the weight elements if required

e.g. regex in stringsearcher

(?<="21" : )[0-9]+\.[0-9]

then rename list elements to attribute

0684Q00000ArKqrQAF.png

Userlevel 2
Badge +17

I read your sample data with CSV reader, this is the result. As you can see there are some unexpected representations such as 82, 105, and 4. How do you translate them?

Could you please explain the rules for mapping all the elements  shown below to desired fields?

col1
"82" : null, "21" : 60.0, "21" : 100.0, "21" : 80.0
"21" : 30.0, "21" : 80.0, "81" : null, "105" : 390.0, "21" : 60.0, "21" : 100.0
"21" : 30.0
"21" : 80.0, "21" : 100.0, "21" : 60.0
"4" : null
"21" : 50.0
"21" : 80.0, "81" : null, "105" : 390.0, "21" : 60.0, "21" : 60.0, "21" : 70.0, "21" : 100.0
"4" : null
"21" : 30.0, "21" : 80.0, "81" : null, "105" : 390.0, "21" : 60.0, "21" : 100.0
"4" : null
"21" : 80.0, "21" : 100.0, "4" : null, "21" : 60.0
"21" : 80.0, "81" : null, "105" : 390.0, "21" : 60.0, "21" : 60.0, "21" : 70.0, "21" : 100.0

 

Reply