代码拉取完成,页面将自动刷新
同步操作将从 王布衣/pandas 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package pandas
import (
"fmt"
)
func parseSelectIndexes(l int, indexes SelectIndexes, colnames []string) ([]int, error) {
var idx []int
switch indexes.(type) {
case []int:
idx = indexes.([]int)
case int:
idx = []int{indexes.(int)}
case []bool:
bools := indexes.([]bool)
if len(bools) != l {
return nil, fmt.Errorf("indexing error: index dimensions mismatch")
}
for i, b := range bools {
if b {
idx = append(idx, i)
}
}
case string:
s := indexes.(string)
i := findInStringSlice(s, colnames)
if i < 0 {
return nil, fmt.Errorf("can't select columns: column name %q not found", s)
}
idx = append(idx, i)
case []string:
xs := indexes.([]string)
for _, s := range xs {
i := findInStringSlice(s, colnames)
if i < 0 {
return nil, fmt.Errorf("can't select columns: column name %q not found", s)
}
idx = append(idx, i)
}
//case Series:
// s := indexes.(Series)
// //if err := s.Err; err != nil {
// // return nil, fmt.Errorf("indexing error: new values has errors: %v", err)
// //}
// //if s.HasNaN() {
// // return nil, fmt.Errorf("indexing error: indexes contain NaN")
// //}
// switch s.Type() {
// case SERIES_TYPE_INT64:
// return s.Int32s()
// case series.Bool:
// bools, err := s.Bool()
// if err != nil {
// return nil, fmt.Errorf("indexing error: %v", err)
// }
// return parseSelectIndexes(l, bools, colnames)
// case series.String:
// xs := indexes.(series.Series).Records()
// return parseSelectIndexes(l, xs, colnames)
// default:
// return nil, fmt.Errorf("indexing error: unknown indexing mode")
// }
default:
return nil, fmt.Errorf("indexing error: unknown indexing mode")
}
return idx, nil
}
// SelectIndexes are the supported indexes used for the DataFrame.Select method. Currently supported are:
//
// int // Matches the given index number
// []int // Matches all given index numbers
// []bool // Matches all columns marked as true
// string // Matches the column with the matching column name
// []string // Matches all columns with the matching column names
// Series [Int] // Same as []int
// Series [Bool] // Same as []bool
// Series [String] // Same as []string
type SelectIndexes any
// Select the given DataFrame columns
func (this DataFrame) Select(indexes SelectIndexes) DataFrame {
if this.Err != nil {
return this
}
idx, err := parseSelectIndexes(this.ncols, indexes, this.Names())
if err != nil {
return DataFrame{Err: fmt.Errorf("can't select columns: %v", err)}
}
columns := make([]Series, len(idx))
for k, i := range idx {
if i < 0 || i >= this.ncols {
return DataFrame{Err: fmt.Errorf("can't select columns: index out of range")}
}
columns[k] = this.columns[i].Copy()
}
nrows, ncols, err := checkColumnsDimensions(columns...)
if err != nil {
return DataFrame{Err: err}
}
this = DataFrame{
columns: columns,
ncols: ncols,
nrows: nrows,
}
colnames := this.Names()
fixColnames(colnames)
for i, colname := range colnames {
this.columns[i].Rename(colname)
}
return this
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。