Documentation ¶
Index ¶
- Constants
- type DataFrame
- func (d *DataFrame) DropCols(col ...string)
- func (d *DataFrame) FormatCols(f func(elem any) any, colName ...string)
- func (d *DataFrame) MapCols(cols ...string) [][]any
- func (d *DataFrame) RenameCols(col map[string]string)
- func (d *DataFrame) Row(row int) series.Series
- func (d *DataFrame) SetType(t map[string]series.Type)
- func (d *DataFrame) WriteXLSX(path string) error
Examples ¶
Constants ¶
View Source
const ( XLSX = "xlsx" XLS = "xls" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DataFrame ¶
DataFrame is https://github.com/go-gota/gota/dataframe simple extend
func Read ¶
Read 读取excel文档,返回 DataFrame
path: 文档路径 sheet: 读取的表格,默认Sheet1
Example ¶
df := Read("test.xls") if df.Error() != nil { panic(df.Error()) } fmt.Println(df) df1 := Read("test.xlsx") if df1.Error() != nil { panic(df1.Error()) } fmt.Println(df1)
Output:
func (*DataFrame) FormatCols ¶
FormatCols 批量格式化列
f(elem any) any:处理函数,elem 为列的每个数值,注意判断数据类型 colName:适用函f数整理的列名
Example ¶
df := DataFrame{} df.DataFrame = dataframe.LoadRecords( [][]string{ {"A", "B", "C", "D"}, {"a", "4", "5.1", "true"}, {"k", "5", "7.0", "true"}, {"k", "4", "6.0", "true"}, {"a", "2", "7.1", "false"}, }, ) df.FormatCols(func(elem any) any { switch v := elem.(type) { case float64: return v + 1 case int: return v - 1 default: return 0 } }, "B", "C", ) fmt.Println(df)
Output:
func (*DataFrame) RenameCols ¶
RenameCols 批量命名
func (*DataFrame) SetType ¶
SetType 设置列的数据类型,如果数据转换失败默认设置为文本类型
Example ¶
df := DataFrame{} df.DataFrame = dataframe.LoadRecords( [][]string{ {"A", "B", "C", "D"}, {"a", "4", "5.1", "true"}, {"k", "5", "7.0", "true"}, {"k", "4", "6.0", "true"}, {"a", "2", "7.1", "false"}, }, ) fmt.Println(df) df.SetType(map[string]series.Type{"D": series.Int, "C": series.String}) fmt.Println(df)
Output:
func (*DataFrame) WriteXLSX ¶
WriteXLSX 将 DataFrame 写入 XLSX 文档中
Example ¶
df := DataFrame{} df.DataFrame = dataframe.LoadRecords( [][]string{ {"A", "B", "C", "D"}, {"a", "4", "5.1", "true"}, {"k", "5", "7.0", "true"}, {"k", "4", "6.0", "true"}, {"a", "2", "7.1", "false"}, }, ) err := df.WriteXLSX("test.xlsx") if err != nil { panic(err) }
Output:
Click to show internal directories.
Click to hide internal directories.