1 Star 4 Fork 11

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dataframe_select.go 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
package pandas
import (
"fmt"
"gitee.com/quant1x/pandas/stat"
)
// Col returns a copy of the Series with the given column name contained in the DataFrame.
// 选取一列
func (self DataFrame) Col(colname string, args ...bool) stat.Series {
inplace := false
if len(args) >= 1 {
inplace = args[0]
}
if self.Err != nil {
return NewSeriesWithType(stat.SERIES_TYPE_INVAILD, "")
}
// Check that colname exist on dataframe
idx := findInStringSlice(colname, self.Names())
if idx < 0 {
return NewSeriesWithType(stat.SERIES_TYPE_INVAILD, "")
}
if inplace {
return self.columns[idx]
}
return self.columns[idx].Copy()
}
func (self DataFrame) ColAsNDArray(colname string) stat.Series {
if self.Err != nil {
return stat.NewSeries[stat.DType]()
}
// Check that colname exist on dataframe
idx := findInStringSlice(colname, self.Names())
if idx < 0 {
return stat.NewSeries[stat.DType]()
}
vs := self.columns[idx].DTypes()
return stat.NewSeries[stat.DType](vs...)
}
// SetNames changes the column names of a DataFrame to the ones passed as an
// argument.
// 修改全部的列名
func (self DataFrame) SetNames(colnames ...string) error {
if len(colnames) != self.ncols {
return fmt.Errorf("setting names: wrong dimensions")
}
for k, s := range colnames {
self.columns[k].Rename(s)
}
return nil
}
// SetName 修改一个series的名称
func (self DataFrame) SetName(from string, to string) {
for _, s := range self.columns {
if s.Name() == from {
s.Rename(to)
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v0.9.13

搜索帮助

344bd9b3 5694891 D2dac590 5694891