将map [string] [] string转换为[] map [string] interface {}

时间:2019-08-12 09:03:58

标签: go gota

我有一个tmp变量,其类型为map [string] [] string,我想使用gota daraframe的LoadMaps功能。但它仅接受[] map [string] interface {}。 现在,我想找到一种将map [string] [] string转换为[] map [string] interface {}的方法。

func main() {
    input := [][]string{
            []string{"b", "3", "abc", "5.3"},
            []string{"a", "4", "efg", "9.1"},
            []string{"b", "4", "abc", "5.3"},
            []string{"c", "3", "hij", "5.5"},
            []string{"a", "2", "abc", "9.2"},
    }

    tmp := map[string][]string{}
    for _, slice := range input {
        if len(slice) <= 1 {
            continue
        }
        //fmt.Println(slice)
        tmp[slice[2]] = append(tmp[slice[2]], slice[0:2]...)
        fmt.Println(reflect.TypeOf(tmp))
    }


    df := dataframe.LoadMaps(tmp)

}

1 个答案:

答案 0 :(得分:0)

您可以将map[string][]string转换为map[string]interface{},然后使用append方法转换为[]map[string]interface{}