我有一个巨大的数据转储,每行如下:
my_vehicle.available
有24小时(全天)和9个不同的目的地。面临的挑战是将其拆分,以便按项目细分。例如:
|hour|number of items|destination|
应该变成这个:
|1|5|Kitchen|
|1|2|Bedroom|
我对如何最好地使用Excel做到这一点空白。如果需要推动,即使不是我的首选解决方案,我也可以使用python转换数据。
答案 0 :(得分:1)
您可以使用for循环遍历所有数据,并为所有9个目的地提供一个计数器变量。使用拆分从数据中获取正确的数据。这是一些可以帮助您的伪代码:
HourVariable = 0
For i = 1 to endOfdata
dHour = split(split(dataline(i),"|")(1),":")(0) 'Get the hour from the dataline
If Hourvariable <> dHour then 'Check if the hour changed. In that case the data for that hour needs to be written and all counters go to 0
If cKitchen > 0 then NewData = NewData & "|" & dHour & "|" & cKitchen & "|Kitchen|" & vbNewLine
If cBedroom > 0 etc...
cKitchen = 0
cBedroom = 0
HourVariable = dHour
Select case split(dataline(i),"|")(3) 'Check which destination is in the current dataline
Case "Kitchen": cKitchen = cKitchen + 1
Case "Bedroom": etc...
End Select
Else 'In other cases, just add to the counters
Select case split(dataline(i),"|")(3) 'Check which destination is in the current dataline
Case "Kitchen": cKitchen = cKitchen + 1
Case "Bedroom": etc...
End Select
End if
next i