insyra

package module
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2024 License: MIT Imports: 17 Imported by: 2

README

Insyra

Test Go version Go Report Card GoDoc MIT license

A next-generation data analysis library for Golang.

logo

繁體中文版 README

Too Fast, Too Lovely, Too Easy To Use.

The Insyra library is a dynamic and versatile tool designed for managing and analyzing data in Go. It offers a rich set of features for data manipulation, statistical calculations, data visualization, and more, making it an essential toolkit for developers handling complex data structures.

[!NOTE] If some functions or methods in the documentation are not working, it may be because the feature is not yet included in the latest release. Please refer to the documentation in the source code of the corresponding version in Releases.

[!IMPORTANT] For any functions or methods not explicitly listed in Insyra documents, it indicates that the feature is still under active development. These experimental features might provide unstable results.

Please refer to our latest updates in Docs folder for more details.

Getting Started

For those new to Golang

[!TIP] Jump to Installation or Quick Example if you are familiar with Go.

  1. Download and install Golang from here.

  2. Set up your editor, we recommend using VSCode.

  3. Open or create a folder for your project, and open it in the editor.

  4. Create a new project by running the following command:

    go mod init your_project_name
    
  5. Install Insyra:

    go get github.com/HazelnutParadise/insyra
    
  6. Create a new file, e.g., main.go, and write the following code:

    package main
    
    import (
        "fmt"
        "github.com/HazelnutParadise/insyra"
    )
    
    func main() {
        // Your code here
    }
    
  7. Run your project:

    go run main.go
    
Installation
  • To start using Insyra, install it with the following command:

    go get github.com/HazelnutParadise/insyra
    
  • Update Insyra to the latest version:

    go get -u github.com/HazelnutParadise/insyra
    

    or

    go get -u github.com/HazelnutParadise/insyra@latest
    
Quick Example
package main

import (
    "fmt"
    "github.com/HazelnutParadise/insyra"
)

func main() {
    dl := insyra.NewDataList(1, 2, 3, 4, 5)
    dl.Append(6)
    fmt.Println("DataList:", dl.Data())
    fmt.Println("Mean:", dl.Mean())
}

DataList

The DataList is the core structure in Insyra, enabling the storage, management, and analysis of dynamic data collections. It offers various methods for data manipulation and statistical analysis.

For a complete list of methods and features, please refer to the DataList Documentation.

DataTable

The DataTable structure provides a tabular data representation, allowing for the storage and manipulation of data in a structured format. It offers methods for data filtering, sorting, and aggregation, making it a powerful tool for data analysis.

You can also convert between DataTables and CSV files with simply one line of code, enabling seamless integration with external data sources.

For a complete list of methods and features, please refer to the DataTable Documentation.

Packages

Insyra also provides several expansion packages, each focusing on a specific aspect of data analysis.

stats

Provides statistical functions for data analysis, including skewness, kurtosis, and moment calculations.

parallel

Offers parallel processing capabilities for data manipulation and analysis. Allows you to execute any function and automatically wait for all goroutines to complete.

plot

Provides a wrapper around the powerful github.com/go-echarts/go-echarts library, designed to simplify data visualization.

gplot

A visualization package based on github.com/gonum/plot. Fast and no need for Chrome.

lpgen

Provides a super simple and intuitive way to generate linear programming (LP) models and save them as .lp files. It supports setting objectives, adding constraints, defining variable bounds, and specifying binary or integer variables.

lp

Fully automatic linear programming (LP) solver using GLPK.

csvxl

Work with Excel and CSV files. Such as convert CSV to Excel.

Advanced Usage

Beyond basic usage, Insyra provides extensive capabilities for handling different data types and performing complex statistical operations. Explore more in the detailed documentation.

Contributing

Contributions are welcome! You can contribute to Insyra by:

  • Issues: Reporting issues or suggesting new features.
  • Pull Requests: Submitting pull requests to enhance the library.
  • Discussions: Sharing your feedback and ideas to improve the project.

Contributors

contributors

License

Insyra is licensed under the MIT License. See the LICENSE file for more information.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Config *configStruct

Functions

func LogDebug

func LogDebug(msg string, args ...interface{})

func LogFatal added in v0.0.1

func LogFatal(msg string, args ...interface{})

func LogInfo

func LogInfo(msg string, args ...interface{})

func LogWarning

func LogWarning(msg string, args ...interface{})

func PowRat added in v0.0.3

func PowRat(base *big.Rat, exponent int) *big.Rat

PowRat calculates the power of a big.Rat. 計算 big.Rat 的次方 (v^n)

func ProcessData

func ProcessData(input interface{}) ([]interface{}, int)

ProcessData processes the input data and returns the data and the length of the data. Returns nil and 0 if the data type is unsupported. Supported data types are slices, IDataList, and pointers to these types.

func SetDefaultConfig

func SetDefaultConfig()

DefaultConfig returns a Config with default values.

func SliceToF64

func SliceToF64(data []interface{}) []float64

SliceToF64 converts a []interface{} to a []float64.

func SqrtRat

func SqrtRat(x *big.Rat) *big.Rat

SqrtRat calculates the square root of a big.Rat. 計算 big.Rat 的平方根

func ToFloat64

func ToFloat64(v interface{}) float64

ToFloat64 converts any numeric value to float64.

func ToFloat64Safe

func ToFloat64Safe(v interface{}) (float64, bool)

ToFloat64Safe tries to convert any numeric value to float64 and returns a boolean indicating success.

Types

type DataList

type DataList struct {
	// contains filtered or unexported fields
}

DataList is a generic dynamic data list.

func NewDataList

func NewDataList(values ...interface{}) *DataList

NewDataList creates a new DataList, supporting both slice and variadic inputs, and flattens the input before storing it.

func (*DataList) Append

func (dl *DataList) Append(values ...interface{})

Append adds a new values to the DataList. The value can be of any type. The value is appended to the end of the DataList.

func (*DataList) Capitalize

func (dl *DataList) Capitalize() *DataList

Capitalize capitalizes the first letter of each string element in the DataList.

func (*DataList) Clear

func (dl *DataList) Clear() *DataList

Clear removes all elements from the DataList and updates the timestamp.

func (*DataList) ClearNaNs added in v0.0.5

func (dl *DataList) ClearNaNs() *DataList

ClearNaNs removes all NaN values from the DataList and updates the timestamp.

func (*DataList) ClearNumbers

func (dl *DataList) ClearNumbers() *DataList

ClearNumbers removes all numeric elements (int, float, etc.) from the DataList and updates the timestamp.

func (*DataList) ClearOutliers added in v0.0.5

func (dl *DataList) ClearOutliers(stdDevs float64) *DataList

ClearOutliers removes values from the DataList that are outside the specified number of standard deviations. This method modifies the original DataList and returns it.

func (*DataList) ClearStrings

func (dl *DataList) ClearStrings() *DataList

ClearStrings removes all string elements from the DataList and updates the timestamp.

func (*DataList) Clone added in v0.0.5

func (dl *DataList) Clone() *DataList

Clone creates a deep copy of the DataList.

func (*DataList) Count added in v0.0.1

func (dl *DataList) Count(value interface{}) int

Count returns the number of occurrences of the specified value in the DataList.

func (*DataList) Data

func (dl *DataList) Data() []interface{}

Data returns the data stored in the DataList.

func (*DataList) Difference added in v0.0.5

func (dl *DataList) Difference() *DataList

Difference calculates the differences between adjacent elements in the DataList.

func (*DataList) DoubleExponentialSmoothing added in v0.0.5

func (dl *DataList) DoubleExponentialSmoothing(alpha, beta float64) *DataList

DoubleExponentialSmoothing applies double exponential smoothing to the DataList. The alpha parameter controls the level smoothing, and the beta parameter controls the trend smoothing. Returns a new DataList containing the smoothed values.

func (*DataList) Drop

func (dl *DataList) Drop(index int) *DataList

Drop removes the element at the specified index from the DataList and updates the timestamp. Returns an error if the index is out of bounds.

func (*DataList) DropAll

func (dl *DataList) DropAll(toDrop ...interface{}) *DataList

DropAll removes all occurrences of the specified values from the DataList. Supports multiple values to drop.

func (*DataList) DropIfContains added in v0.0.2

func (dl *DataList) DropIfContains(value interface{}) *DataList

DropIfContains removes all elements from the DataList that contain the specified value.

func (*DataList) ExponentialSmoothing added in v0.0.5

func (dl *DataList) ExponentialSmoothing(alpha float64) *DataList

ExponentialSmoothing applies exponential smoothing to the DataList. The alpha parameter controls the smoothing factor. Returns a new DataList containing the smoothed values.

func (*DataList) FillNaNWithMean added in v0.0.5

func (dl *DataList) FillNaNWithMean() *DataList

FillNaNWithMean replaces all NaN values in the DataList with the mean value. Directly modifies the DataList.

func (*DataList) Filter

func (dl *DataList) Filter(filterFunc func(interface{}) bool) *DataList

Filter filters the DataList based on a custom filter function provided by the user. The filter function should return true for elements that should be included in the result.

func (*DataList) FindAll

func (dl *DataList) FindAll(value interface{}) []int

FindAll returns a slice of all the indices where the specified value is found in the DataList using parallel processing. If the value is not found, it returns an empty slice.

func (*DataList) FindFirst

func (dl *DataList) FindFirst(value interface{}) interface{}

FindFirst returns the index of the first occurrence of the specified value in the DataList. If the value is not found, it returns nil.

func (*DataList) FindLast

func (dl *DataList) FindLast(value interface{}) interface{}

FindLast returns the index of the last occurrence of the specified value in the DataList. If the value is not found, it returns nil.

func (*DataList) GMean

func (dl *DataList) GMean() float64

GMean calculates the geometric mean of the DataList. Returns the geometric mean. Returns math.NaN() if the DataList is empty or if no elements can be converted to float64.

func (*DataList) Get

func (dl *DataList) Get(index int) interface{}

Get retrieves the value at the specified index in the DataList. Supports negative indexing. Returns nil if the index is out of bounds. Returns the value at the specified index.

func (*DataList) GetCreationTimestamp

func (dl *DataList) GetCreationTimestamp() int64

GetCreationTimestamp returns the creation time of the DataList in Unix timestamp.

func (*DataList) GetLastModifiedTimestamp

func (dl *DataList) GetLastModifiedTimestamp() int64

GetLastModifiedTimestamp returns the last updated time of the DataList in Unix timestamp.

func (*DataList) GetName

func (dl *DataList) GetName() string

GetName returns the name of the DataList.

func (*DataList) HermiteInterpolation added in v0.0.5

func (dl *DataList) HermiteInterpolation(x float64, derivatives []float64) float64

HermiteInterpolation performs Hermite interpolation for the given x value using the DataList.

func (*DataList) IQR

func (dl *DataList) IQR() float64

IQR calculates the interquartile range of the DataList. Returns math.NaN() if the DataList is empty or if Q1 or Q3 cannot be calculated. Returns the interquartile range (Q3 - Q1) as a float64.

func (*DataList) InsertAt

func (dl *DataList) InsertAt(index int, value interface{})

InsertAt inserts a value at the specified index in the DataList. If the index is out of bounds, the value is appended to the end of the list.

func (*DataList) LagrangeInterpolation added in v0.0.5

func (dl *DataList) LagrangeInterpolation(x float64) float64

LagrangeInterpolation performs Lagrange interpolation for the given x value using the DataList.

func (*DataList) Len

func (dl *DataList) Len() int

func (*DataList) LinearInterpolation added in v0.0.5

func (dl *DataList) LinearInterpolation(x float64) float64

LinearInterpolation performs linear interpolation for the given x value using the DataList.

func (*DataList) Lower

func (dl *DataList) Lower() *DataList

Lower converts all string elements in the DataList to lowercase.

func (*DataList) MAD added in v0.0.5

func (dl *DataList) MAD() float64

MAD calculates the mean absolute deviation of the DataList. Returns math.NaN() if the DataList is empty or if no valid elements can be used.

func (*DataList) Max

func (dl *DataList) Max() float64

Max returns the maximum value in the DataList. Returns math.NaN() if the DataList is empty or if no elements can be converted to float64.

func (*DataList) Mean

func (dl *DataList) Mean() float64

Mean calculates the arithmetic mean of the DataList. Returns math.NaN() if the DataList is empty or if no elements can be converted to float64.

func (*DataList) Median

func (dl *DataList) Median() float64

Median calculates the median of the DataList. Returns math.NaN() if the DataList is empty or if no valid elements can be used.

func (*DataList) Min

func (dl *DataList) Min() float64

Min returns the minimum value in the DataList. Returns math.NaN() if the DataList is empty or if no elements can be converted to float64.

func (*DataList) Mode

func (dl *DataList) Mode() float64

Mode calculates the mode of the DataList. Only works with numeric data types. Returns math.NaN() if the DataList is empty or if no valid elements can be used.

func (*DataList) MovingAverage added in v0.0.5

func (dl *DataList) MovingAverage(windowSize int) *DataList

MovingAverage calculates the moving average of the DataList using a specified window size. Returns a new DataList containing the moving average values.

func (*DataList) MovingStdev added in v0.0.5

func (dl *DataList) MovingStdev(windowSize int) *DataList

MovingStdDev calculates the moving standard deviation for the DataList using a specified window size.

func (*DataList) NearestNeighborInterpolation added in v0.0.5

func (dl *DataList) NearestNeighborInterpolation(x float64) float64

NearestNeighborInterpolation performs nearest-neighbor interpolation for the given x value using the DataList.

func (*DataList) NewtonInterpolation added in v0.0.5

func (dl *DataList) NewtonInterpolation(x float64) float64

NewtonInterpolation performs Newton's interpolation for the given x value using the DataList.

func (*DataList) Normalize added in v0.0.5

func (dl *DataList) Normalize() *DataList

Normalize normalizes the data in the DataList, skipping NaN values. Directly modifies the DataList.

func (*DataList) ParseNumbers

func (dl *DataList) ParseNumbers() *DataList

ParseNumbers attempts to parse all string elements in the DataList to numeric types. If parsing fails, the element is left unchanged.

func (*DataList) ParseStrings

func (dl *DataList) ParseStrings() *DataList

ParseStrings converts all elements in the DataList to strings.

func (*DataList) Percentile

func (dl *DataList) Percentile(p float64) float64

Percentile calculates the percentile based on the input value (0 to 100). Returns the percentile value as float64, or math.NaN() if the DataList is empty or invalid percentile is provided.

func (*DataList) Pop

func (dl *DataList) Pop() interface{}

Pop removes and returns the last element from the DataList. Returns the last element. Returns nil if the DataList is empty.

func (*DataList) QuadraticInterpolation added in v0.0.5

func (dl *DataList) QuadraticInterpolation(x float64) float64

QuadraticInterpolation performs quadratic interpolation for the given x value using the DataList.

func (*DataList) Quartile

func (dl *DataList) Quartile(q int) float64

Quartile calculates the quartile based on the input value (1 to 3). 1 corresponds to the first quartile (Q1), 2 to the median (Q2), and 3 to the third quartile (Q3). This implementation uses percentiles to compute quartiles.

func (*DataList) Range

func (dl *DataList) Range() float64

Range calculates the range of the DataList. Returns math.NaN() if the DataList is empty or if Max or Min cannot be calculated.

func (*DataList) Rank added in v0.0.4

func (dl *DataList) Rank() *DataList

Rank assigns ranks to the elements in the DataList.

func (*DataList) ReplaceAll

func (dl *DataList) ReplaceAll(oldValue, newValue interface{})

ReplaceAll replaces all occurrences of oldValue with newValue in the DataList. If oldValue is not found, no changes are made.

func (*DataList) ReplaceFirst

func (dl *DataList) ReplaceFirst(oldValue, newValue interface{})

ReplaceFirst replaces the first occurrence of oldValue with newValue.

func (*DataList) ReplaceLast

func (dl *DataList) ReplaceLast(oldValue, newValue interface{})

ReplaceLast replaces the last occurrence of oldValue with newValue.

func (*DataList) ReplaceOutliers added in v0.0.5

func (dl *DataList) ReplaceOutliers(stdDevs float64, replacement float64) *DataList

ReplaceOutliers replaces outliers in the DataList with the specified replacement value (e.g., mean, median).

func (*DataList) Reverse

func (dl *DataList) Reverse() *DataList

Reverse reverses the order of the elements in the DataList.

func (*DataList) SetName

func (dl *DataList) SetName(newName string) *DataList

SetName sets the name of the DataList.

func (*DataList) Sort

func (dl *DataList) Sort(ascending ...bool) *DataList

Sort sorts the DataList using a mixed sorting logic. It handles string, numeric (including all integer and float types), and time data types. If sorting fails, it restores the original order.

func (*DataList) Standardize added in v0.0.5

func (dl *DataList) Standardize() *DataList

Standardize standardizes the data in the DataList. Directly modifies the DataList.

func (*DataList) Stdev

func (dl *DataList) Stdev() float64

Stdev calculates the standard deviation (sample) of the DataList. Returns math.NaN() if the DataList is empty or if no valid elements can be used.

func (*DataList) StdevP

func (dl *DataList) StdevP() float64

StdevP calculates the standard deviation (population) of the DataList. Returns math.NaN() if the DataList is empty or if no valid elements can be used.

func (*DataList) Sum added in v0.0.1

func (dl *DataList) Sum() float64

Sum calculates the sum of all elements in the DataList. Returns math.NaN() if the DataList is empty or if no elements can be converted to float64.

func (*DataList) ToF64Slice

func (dl *DataList) ToF64Slice() []float64

ToF64Slice converts the DataList to a float64 slice. Returns the float64 slice. Returns nil if the DataList is empty. ToF64Slice converts the DataList to a float64 slice.

func (*DataList) ToStringSlice

func (dl *DataList) ToStringSlice() []string

ToStringSlice converts the DataList to a string slice. Returns the string slice. Returns nil if the DataList is empty.

func (*DataList) Update

func (dl *DataList) Update(index int, newValue interface{})

Update replaces the value at the specified index with the new value.

func (*DataList) Upper

func (dl *DataList) Upper() *DataList

Upper converts all string elements in the DataList to uppercase.

func (*DataList) Var

func (dl *DataList) Var() float64

Var calculates the variance (sample variance) of the DataList. Returns math.NaN() if the DataList is empty or if not enough valid elements are available.

func (*DataList) VarP

func (dl *DataList) VarP() float64

VarP calculates the variance (population variance) of the DataList. Returns math.NaN() if the DataList is empty or if no valid elements can be used.

func (*DataList) WeightedMean added in v0.0.5

func (dl *DataList) WeightedMean(weights interface{}) float64

WeightedMean calculates the weighted mean of the DataList using the provided weights. The weights parameter should be a slice or a DataList of the same length as the DataList. Returns math.NaN() if the DataList is empty, weights are invalid, or if no valid elements can be used.

func (*DataList) WeightedMovingAverage added in v0.0.5

func (dl *DataList) WeightedMovingAverage(windowSize int, weights interface{}) *DataList

WeightedMovingAverage applies a weighted moving average to the DataList with a given window size. The weights parameter should be a slice or a DataList of the same length as the window size. Returns a new DataList containing the weighted moving average values.

type DataTable added in v0.0.1

type DataTable struct {
	// contains filtered or unexported fields
}

func NewDataTable added in v0.0.1

func NewDataTable(columns ...*DataList) *DataTable

func (*DataTable) AppendColumns added in v0.0.1

func (dt *DataTable) AppendColumns(columns ...*DataList) *DataTable

AppendColumns appends columns to the DataTable, with each column represented by a DataList. If the columns are shorter than the existing columns, nil values will be appended to match the length. If the columns are longer than the existing columns, the existing columns will be extended with nil values.

func (*DataTable) AppendRowsByIndex added in v0.0.1

func (dt *DataTable) AppendRowsByIndex(rowsData ...map[string]interface{}) *DataTable

AppendRowsByIndex appends rows to the DataTable, with each row represented by a map of column index and value. If the rows are shorter than the existing columns, nil values will be appended to match the length. If the rows are longer than the existing columns, the existing columns will be extended with nil values.

func (*DataTable) AppendRowsByName added in v0.0.1

func (dt *DataTable) AppendRowsByName(rowsData ...map[string]interface{}) *DataTable

AppendRowsByName appends rows to the DataTable, with each row represented by a map of column name and value. If the rows are shorter than the existing columns, nil values will be appended to match the length. If the rows are longer than the existing columns, the existing columns will be extended with nil values.

func (*DataTable) AppendRowsFromDataList added in v0.0.1

func (dt *DataTable) AppendRowsFromDataList(rowsData ...*DataList) *DataTable

AppendRowsFromDataList appends rows to the DataTable, with each row represented by a DataList. If the rows are shorter than the existing columns, nil values will be appended to match the length. If the rows are longer than the existing columns, the existing columns will be extended with nil values.

func (*DataTable) Count added in v0.0.4

func (dt *DataTable) Count(value interface{}) int

Count returns the number of occurrences of the given value in the DataTable.

func (*DataTable) Data added in v0.0.1

func (dt *DataTable) Data(useNamesAsKeys ...bool) map[string][]interface{}

func (*DataTable) DropColumnsByIndex added in v0.0.1

func (dt *DataTable) DropColumnsByIndex(columnIndices ...string)

DropColumnsByIndex drops columns by their index names.

func (*DataTable) DropColumnsByName added in v0.0.1

func (dt *DataTable) DropColumnsByName(columnNames ...string)

DropColumnsByName drops columns by their names.

func (*DataTable) DropColumnsByNumber added in v0.0.8

func (dt *DataTable) DropColumnsByNumber(columnIndices ...int)

DropColumnsByNumber drops columns by their number.

func (*DataTable) DropColumnsContainNil added in v0.0.2

func (dt *DataTable) DropColumnsContainNil()

DropColumnsContainNil drops columns that contain nil elements.

func (*DataTable) DropColumnsContainNumbers added in v0.0.2

func (dt *DataTable) DropColumnsContainNumbers()

DropColumnsContainNumbers drops columns that contain number elements.

func (*DataTable) DropColumnsContainStringElements added in v0.0.2

func (dt *DataTable) DropColumnsContainStringElements()

DropColumnsContainStringElements drops columns that contain string elements.

func (*DataTable) DropRowsByIndex added in v0.0.1

func (dt *DataTable) DropRowsByIndex(rowIndices ...int)

DropRowsByIndex drops rows by their indices.

func (*DataTable) DropRowsByName added in v0.0.1

func (dt *DataTable) DropRowsByName(rowNames ...string)

DropRowsByName drops rows by their names.

func (*DataTable) DropRowsContainNil added in v0.0.2

func (dt *DataTable) DropRowsContainNil()

DropRowsContainNil drops rows that contain nil elements.

func (*DataTable) DropRowsContainNumbers added in v0.0.2

func (dt *DataTable) DropRowsContainNumbers()

DropRowsContainNumbers drops rows that contain number elements.

func (*DataTable) DropRowsContainStringElements added in v0.0.2

func (dt *DataTable) DropRowsContainStringElements()

DropRowsContainStringElements drops rows that contain string elements.

func (*DataTable) Filter added in v0.0.2

func (dt *DataTable) Filter(filterFunc FilterFunc) *DataTable

Filter applies a custom filter function to the DataTable and returns the filtered DataTable.

func (*DataTable) FilterByColumnIndexEqualTo added in v0.0.2

func (dt *DataTable) FilterByColumnIndexEqualTo(columnLetter string) *DataTable

FilterByColumnIndexEqualTo filters to only keep the column with the specified index.

func (*DataTable) FilterByColumnIndexGreaterThan added in v0.0.2

func (dt *DataTable) FilterByColumnIndexGreaterThan(columnLetter string) *DataTable

FilterByColumnIndexGreaterThan filters columns with index greater than the specified column.

func (*DataTable) FilterByColumnIndexGreaterThanOrEqualTo added in v0.0.2

func (dt *DataTable) FilterByColumnIndexGreaterThanOrEqualTo(columnLetter string) *DataTable

FilterByColumnIndexGreaterThanOrEqualTo filters columns with index greater than or equal to the specified column.

func (*DataTable) FilterByColumnIndexLessThan added in v0.0.2

func (dt *DataTable) FilterByColumnIndexLessThan(columnLetter string) *DataTable

FilterByColumnIndexLessThan filters columns with index less than the specified column.

func (*DataTable) FilterByColumnIndexLessThanOrEqualTo added in v0.0.2

func (dt *DataTable) FilterByColumnIndexLessThanOrEqualTo(columnLetter string) *DataTable

FilterByColumnIndexLessThanOrEqualTo filters columns with index less than or equal to the specified column.

func (*DataTable) FilterByColumnNameContains added in v0.0.2

func (dt *DataTable) FilterByColumnNameContains(substring string) *DataTable

FilterByColumnNameContains filters columns whose name contains the specified substring.

func (*DataTable) FilterByColumnNameEqualTo added in v0.0.2

func (dt *DataTable) FilterByColumnNameEqualTo(columnName string) *DataTable

FilterByColumnNameEqualTo filters to only keep the column with the specified name.

func (*DataTable) FilterByCustomElement added in v0.0.2

func (dt *DataTable) FilterByCustomElement(filterFunc func(value interface{}) bool) *DataTable

FilterByCustomElement filters the table based on a custom function applied to each element.

func (*DataTable) FilterByRowIndexEqualTo added in v0.0.2

func (dt *DataTable) FilterByRowIndexEqualTo(index int) *DataTable

FilterByRowIndexEqualTo filters to only keep the row with the specified index.

func (*DataTable) FilterByRowIndexGreaterThan added in v0.0.2

func (dt *DataTable) FilterByRowIndexGreaterThan(threshold int) *DataTable

FilterByRowIndexGreaterThan filters rows with index greater than the specified threshold.

func (*DataTable) FilterByRowIndexGreaterThanOrEqualTo added in v0.0.2

func (dt *DataTable) FilterByRowIndexGreaterThanOrEqualTo(threshold int) *DataTable

FilterByRowIndexGreaterThanOrEqualTo filters rows with index greater than or equal to the specified threshold.

func (*DataTable) FilterByRowIndexLessThan added in v0.0.2

func (dt *DataTable) FilterByRowIndexLessThan(threshold int) *DataTable

FilterByRowIndexLessThan filters rows with index less than the specified threshold.

func (*DataTable) FilterByRowIndexLessThanOrEqualTo added in v0.0.2

func (dt *DataTable) FilterByRowIndexLessThanOrEqualTo(threshold int) *DataTable

FilterByRowIndexLessThanOrEqualTo filters rows with index less than or equal to the specified threshold.

func (*DataTable) FilterByRowNameContains added in v0.0.2

func (dt *DataTable) FilterByRowNameContains(substring string) *DataTable

FilterByRowNameContains filters rows whose name contains the specified substring.

func (*DataTable) FilterByRowNameEqualTo added in v0.0.2

func (dt *DataTable) FilterByRowNameEqualTo(rowName string) *DataTable

FilterByRowNameEqualTo filters to only keep the row with the specified name.

func (*DataTable) FindColumnsIfAllElementsContainSubstring added in v0.0.2

func (dt *DataTable) FindColumnsIfAllElementsContainSubstring(substring string) []string

FindColumnsIfAllElementsContainSubstring returns the indices of columns that contain all elements that contain the given substring.

func (*DataTable) FindColumnsIfAnyElementContainsSubstring added in v0.0.2

func (dt *DataTable) FindColumnsIfAnyElementContainsSubstring(substring string) []string

FindColumnsIfAnyElementContainsSubstring returns the indices of columns that contain at least one element that contains the given substring.

func (*DataTable) FindColumnsIfContains added in v0.0.2

func (dt *DataTable) FindColumnsIfContains(value interface{}) []string

FindColumnsIfContains returns the indices of columns that contain the given element.

func (*DataTable) FindColumnsIfContainsAll added in v0.0.2

func (dt *DataTable) FindColumnsIfContainsAll(values ...interface{}) []string

FindColumnsIfContainsAll returns the indices of columns that contain all the given elements.

func (*DataTable) FindRowsIfAllElementsContainSubstring added in v0.0.2

func (dt *DataTable) FindRowsIfAllElementsContainSubstring(substring string) []int

FindRowsIfAllElementsContainSubstring returns the indices of rows that contain all elements that contain the given substring.

func (*DataTable) FindRowsIfAnyElementContainsSubstring added in v0.0.2

func (dt *DataTable) FindRowsIfAnyElementContainsSubstring(substring string) []int

FindRowsIfAnyElementContainsSubstring returns the indices of rows that contain at least one element that contains the given substring.

func (*DataTable) FindRowsIfContains added in v0.0.2

func (dt *DataTable) FindRowsIfContains(value interface{}) []int

FindRowsIfContains returns the indices of rows that contain the given element.

func (*DataTable) FindRowsIfContainsAll added in v0.0.2

func (dt *DataTable) FindRowsIfContainsAll(values ...interface{}) []int

FindRowsIfContainsAll returns the indices of rows that contain all the given elements.

func (*DataTable) GetColumn added in v0.0.2

func (dt *DataTable) GetColumn(index string) *DataList

GetColumn returns a new DataList containing the data of the column with the given index.

func (*DataTable) GetColumnByNumber added in v0.0.6

func (dt *DataTable) GetColumnByNumber(index int) *DataList

func (*DataTable) GetCreationTimestamp added in v0.0.1

func (dt *DataTable) GetCreationTimestamp() int64

func (*DataTable) GetElement added in v0.0.2

func (dt *DataTable) GetElement(rowIndex int, columnIndex string) interface{}

GetElement returns the element at the given row and column index.

func (*DataTable) GetElementByNumberIndex added in v0.0.7

func (dt *DataTable) GetElementByNumberIndex(rowIndex int, columnIndex int) interface{}

func (*DataTable) GetLastModifiedTimestamp added in v0.0.1

func (dt *DataTable) GetLastModifiedTimestamp() int64

func (*DataTable) GetRow added in v0.0.2

func (dt *DataTable) GetRow(index int) *DataList

GetRow returns a new DataList containing the data of the row with the given index.

func (*DataTable) GetRowNameByIndex added in v0.0.2

func (dt *DataTable) GetRowNameByIndex(index int) string

GetRowNameByIndex returns the name of the row at the given index.

func (*DataTable) LoadFromCSV added in v0.0.3

func (dt *DataTable) LoadFromCSV(filePath string, setFirstColumnToRowNames bool, setFirstRowToColumnNames bool) error

LoadFromCSV loads a CSV file into a DataTable, with options to set the first column as row names and the first row as column names.

func (*DataTable) Mean added in v0.0.7

func (dt *DataTable) Mean() interface{}

func (*DataTable) SetColumnToRowNames added in v0.0.7

func (dt *DataTable) SetColumnToRowNames(columnIndex string) *DataTable

SetColumnToRowNames sets the row names to the values of the specified column and drops the column.

func (*DataTable) SetRowNameByIndex added in v0.0.2

func (dt *DataTable) SetRowNameByIndex(index int, name string)

func (*DataTable) SetRowToColumnNames added in v0.0.7

func (dt *DataTable) SetRowToColumnNames(rowIndex int) *DataTable

SetRowToColumnNames sets the column names to the values of the specified row and drops the row.

func (*DataTable) Show added in v0.0.1

func (dt *DataTable) Show()

func (*DataTable) ShowTypes added in v0.0.3

func (dt *DataTable) ShowTypes()

func (*DataTable) Size added in v0.0.4

func (dt *DataTable) Size() (int, int)

Size returns the number of rows and columns in the DataTable.

func (*DataTable) ToCSV added in v0.0.3

func (dt *DataTable) ToCSV(filePath string, setRowNamesToFirstColumn bool, setColumnNamesToFirstRow bool) error

ToCSV converts the DataTable to CSV format and writes it to the provided file path. The function accepts two parameters: - filePath: the file path to write the CSV file to - setRowNamesToFirstColumn: if true, the first column will be used as row names - setColumnNamesToFirstRow: if true, the first row will be used as column names

func (*DataTable) Transpose added in v0.0.8

func (dt *DataTable) Transpose() *DataTable

Transpose transposes the DataTable, converting rows into columns and vice versa.

func (*DataTable) UpdateColumn added in v0.0.2

func (dt *DataTable) UpdateColumn(index string, dl *DataList)

UpdateColumn updates the column with the given index.

func (*DataTable) UpdateColumnByNumber added in v0.0.8

func (dt *DataTable) UpdateColumnByNumber(index int, dl *DataList)

UpdateColumnByNumber updates the column at the given index.

func (*DataTable) UpdateElement added in v0.0.2

func (dt *DataTable) UpdateElement(rowIndex int, columnIndex string, value interface{})

UpdateElement updates the element at the given row and column index.

func (*DataTable) UpdateRow added in v0.0.2

func (dt *DataTable) UpdateRow(index int, dl *DataList)

UpdateRow updates the row at the given index.

type F64orRat added in v0.0.9

type F64orRat interface {
	float64 | *big.Rat
}

type FilterFunc added in v0.0.2

type FilterFunc func(rowIndex int, columnIndex string, value interface{}) bool

FilterFunc is a custom filter function that takes the row index, column name, and value as input and returns a boolean.

type IDataList

type IDataList interface {
	GetCreationTimestamp() int64
	GetLastModifiedTimestamp() int64

	GetName() string
	SetName(string) *DataList
	Data() []interface{}
	Append(values ...interface{})
	Get(index int) interface{}
	Clone() *DataList
	Count(value interface{}) int
	Update(index int, value interface{})
	InsertAt(index int, value interface{})
	FindFirst(interface{}) interface{}
	FindLast(interface{}) interface{}
	FindAll(interface{}) []int
	Filter(func(interface{}) bool) *DataList
	ReplaceFirst(interface{}, interface{})
	ReplaceLast(interface{}, interface{})
	ReplaceAll(interface{}, interface{})
	ReplaceOutliers(float64, float64) *DataList
	Pop() interface{}
	Drop(index int) *DataList
	DropAll(...interface{}) *DataList
	DropIfContains(interface{}) *DataList
	Clear() *DataList
	ClearStrings() *DataList
	ClearNumbers() *DataList
	ClearNaNs() *DataList
	ClearOutliers(float64) *DataList
	Normalize() *DataList
	Standardize() *DataList
	FillNaNWithMean() *DataList
	MovingAverage(int) *DataList
	WeightedMovingAverage(int, interface{}) *DataList
	ExponentialSmoothing(float64) *DataList
	DoubleExponentialSmoothing(float64, float64) *DataList
	MovingStdev(int) *DataList
	Len() int
	Sort(acending ...bool) *DataList
	Rank() *DataList
	Reverse() *DataList
	Upper() *DataList
	Lower() *DataList
	Capitalize() *DataList

	// Statistics
	Sum() float64
	Max() float64
	Min() float64
	Mean() float64
	WeightedMean(weights interface{}) float64
	GMean() float64
	Median() float64
	Mode() float64
	MAD() float64
	Stdev() float64
	StdevP() float64
	Var() float64
	VarP() float64
	Range() float64
	Quartile(int) float64
	IQR() float64
	Percentile(float64) float64
	Difference() *DataList

	// conversion
	ParseNumbers() *DataList
	ParseStrings() *DataList
	ToF64Slice() []float64
	ToStringSlice() []string

	// Interpolation
	LinearInterpolation(float64) float64
	QuadraticInterpolation(float64) float64
	LagrangeInterpolation(float64) float64
	NearestNeighborInterpolation(float64) float64
	NewtonInterpolation(float64) float64
	HermiteInterpolation(float64, []float64) float64
	// contains filtered or unexported methods
}

IDataList defines the behavior expected from a DataList.

type IDataTable added in v0.0.1

type IDataTable interface {
	AppendColumns(columns ...*DataList) *DataTable
	AppendRowsFromDataList(rowsData ...*DataList) *DataTable
	AppendRowsByIndex(rowsData ...map[string]interface{}) *DataTable
	AppendRowsByName(rowsData ...map[string]interface{}) *DataTable
	GetElement(rowIndex int, columnIndex string) interface{}
	GetElementByNumberIndex(rowIndex int, columnIndex int) interface{}
	GetColumn(index string) *DataList
	GetColumnByNumber(index int) *DataList
	GetRow(index int) *DataList
	UpdateElement(rowIndex int, columnIndex string, value interface{})
	UpdateColumn(index string, dl *DataList)
	UpdateColumnByNumber(index int, dl *DataList)
	UpdateRow(index int, dl *DataList)
	SetColumnToRowNames(columnIndex string) *DataTable
	SetRowToColumnNames(rowIndex int) *DataTable
	FindRowsIfContains(value interface{}) []int
	FindRowsIfContainsAll(values ...interface{}) []int
	FindRowsIfAnyElementContainsSubstring(substring string) []int
	FindRowsIfAllElementsContainSubstring(substring string) []int
	FindColumnsIfContains(value interface{}) []string
	FindColumnsIfContainsAll(values ...interface{}) []string
	FindColumnsIfAnyElementContainsSubstring(substring string) []string
	FindColumnsIfAllElementsContainSubstring(substring string) []string
	DropColumnsByName(columnNames ...string)
	DropColumnsByIndex(columnIndices ...string)
	DropColumnsByNumber(columnIndices ...int)
	DropColumnsContainStringElements()
	DropColumnsContainNumbers()
	DropColumnsContainNil()
	DropRowsByIndex(rowIndices ...int)
	DropRowsByName(rowNames ...string)
	DropRowsContainStringElements()
	DropRowsContainNumbers()
	DropRowsContainNil()
	Data(useNamesAsKeys ...bool) map[string][]interface{}
	Show()
	ShowTypes()
	GetRowNameByIndex(index int) string
	SetRowNameByIndex(index int, name string)
	GetCreationTimestamp() int64
	GetLastModifiedTimestamp() int64

	// Statistics
	Size() (int, int)
	Count(value interface{}) int
	Mean() interface{}

	// Conversion
	Transpose() *DataTable

	// Filters
	Filter(filterFunc FilterFunc) *DataTable
	FilterByCustomElement(f func(value interface{}) bool) *DataTable
	FilterByColumnIndexGreaterThan(threshold string) *DataTable
	FilterByColumnIndexGreaterThanOrEqualTo(threshold string) *DataTable
	FilterByColumnIndexLessThan(threshold string) *DataTable
	FilterByColumnIndexLessThanOrEqualTo(threshold string) *DataTable
	FilterByColumnIndexEqualTo(index string) *DataTable
	FilterByColumnNameEqualTo(name string) *DataTable
	FilterByColumnNameContains(substring string) *DataTable
	FilterByRowNameEqualTo(name string) *DataTable
	FilterByRowNameContains(substring string) *DataTable
	FilterByRowIndexGreaterThan(threshold int) *DataTable
	FilterByRowIndexGreaterThanOrEqualTo(threshold int) *DataTable
	FilterByRowIndexLessThan(threshold int) *DataTable
	FilterByRowIndexLessThanOrEqualTo(threshold int) *DataTable
	FilterByRowIndexEqualTo(index int) *DataTable

	// CSV
	ToCSV(filePath string, setRowNamesToFirstColumn bool, setColumnNamesToFirstRow bool) error
	LoadFromCSV(filePath string, setFirstColumnToRowNames bool, setFirstRowToColumnNames bool) error
	// contains filtered or unexported methods
}

func ConvertLongDataToWide added in v0.0.8

func ConvertLongDataToWide(data, factor IDataList, independents []IDataList, aggFunc func([]float64) float64) IDataTable

ConvertLongDataToWide converts long data to wide data. data: 觀測值(依變數) factor: 因子 independents: 自變數 aggFunc: 聚合函數 Return DataTable.

type LogLevel

type LogLevel int
const (
	// LogLevelDebug is the log level for debug messages.
	LogLevelDebug LogLevel = iota
	// LogLevelInfo is the log level for info messages.
	LogLevelInfo
	// LogLevelWarning is the log level for warning messages.
	LogLevelWarning
	// LogLevelFatal is the log level for fatal messages.
	LogLevelFatal
)

type NameManager

type NameManager struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL