在数组中打印不同的值

时间:2018-03-15 00:42:56

标签: azure-application-insights ms-app-analytics

我有一个列是一个数组,并希望打印出不同的计数

Event
| project colors

展示OutPut

["Red", "Green", "Green", "Red"]
["Yellow", "Yellow", "Yellow", "Yellow"]

预期

["Red", "Green", "Green", "Red"] , 2
["Yellow", "Yellow", "Yellow", "Yellow"], 1

1 个答案:

答案 0 :(得分:0)

这是我认为您想要的,使用A = pd.DataFrame({'Error Time':array1[:,0],'Err ID':array1[:,1],'Alert Type':array1[:,2]}) B = pd.DataFrame({'Recover Time':array2[:,0], 'Rec ID':array2[:,1]}) data_array = pd.concat([A,B], axis=1) #Joins the two arrays together pd.to_datetime(data_array['Error Time'],format='%H:%M:%S.%f').dt.time pd.to_datetime(data_array['Recover Time'],format='%H:%M:%S.%f').dt.time #data_array = data_array.sort_values(by=['Error Time']) col_size = len(data_array['Error Time']) for i in range(col_size): if data_array.iloc[i,1] == data_array.iloc[i,3]: indexA.append(i) else: for j in range(col_size): if data_array.iloc[i,1] == data_array.iloc[j,3]: if indexA.count(j) > 0: j = j + 1 else: indexA.append(j) break for k in range(col_size): if indexA.count(k)== 0: indexA.append(k) data_array = data_array.reindex(['Error Time', 'Error ID', 'Alert Type],index=[indexA]) todynamic以及mvexpand,(和summarize来创建输入数据)

datatable

将输出您在问题中的内容:

// create your sample data using datatable to make a 'fake' table
datatable (colors: string) [
'["Red", "Green", "Green", "Red"]',
'["Yellow", "Yellow", "Yellow", "Yellow"]'
]
// this part is answering your question
| extend c = todynamic(colors) // turns colors into arrays
| mvexpand c // expands all the values out of colors into their own rows (but each column value is still "dynamic" type)
| extend c = tostring(c) // turn the dynamic c column to strings to summarize the values
| summarize ["Count"] = dcount(c) by colors // count up distinct c values by each row