gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 03:36:07 25 4
gpt4 key购买 nike

我有一个类型为 map[string][]string 的 tmp 变量,我想使用 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)

}

最佳答案

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

关于go - 将 map[string][]string 转换为 []map[string]interface{},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57458294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com