Ai
2 Star 4 Fork 17

王布衣/pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dataframe_map.go 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-02-10 10:42 +08:00 . interface{}改为any
package pandas
import (
"fmt"
"sort"
)
// LoadMaps creates a new DataFrame based on the given maps. This function assumes
// that every map on the array represents a row of observations.
func LoadMaps(maps []map[string]any, options ...LoadOption) DataFrame {
if len(maps) == 0 {
return DataFrame{Err: fmt.Errorf("load maps: empty array")}
}
inStrSlice := func(i string, s []string) bool {
for _, v := range s {
if v == i {
return true
}
}
return false
}
// Detect all colnames
var colnames []string
for _, v := range maps {
for k := range v {
if exists := inStrSlice(k, colnames); !exists {
colnames = append(colnames, k)
}
}
}
sort.Strings(colnames)
records := make([][]string, len(maps)+1)
records[0] = colnames
for k, m := range maps {
row := make([]string, len(colnames))
for i, colname := range colnames {
element := ""
val, ok := m[colname]
if ok {
element = fmt.Sprint(val)
}
row[i] = element
}
records[k+1] = row
}
return LoadRecords(records, options...)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.5.2

搜索帮助