https://github.com/tpkn/csv-tools
Easily extract and access columns from a csv file
https://github.com/tpkn/csv-tools
Last synced: 3 months ago
JSON representation
Easily extract and access columns from a csv file
- Host: GitHub
- URL: https://github.com/tpkn/csv-tools
- Owner: tpkn
- License: mit
- Created: 2020-11-19T12:20:00.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-21T00:54:58.000Z (over 4 years ago)
- Last Synced: 2025-01-14T08:12:51.014Z (4 months ago)
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CSV Tools
Easily extract and access columns from a csv file## FindColumns()
Keep in mind that the indexes in the results have the same sequence as in the `find_this` variable:
```go
var clean = true
var find_this = []string { "Name", "Date", "Counter" }
var header_row = []string { "Counter", "Name", "Date" }c, i, _ := csvtools.FindColumns(find_this, header_row, clean)
```Result will be:
```go
[ "Name", "Date", "Counter" ], [ 1, 2, 0 ]
```### find_this
**Type**: `[]string`
A slice of columns to find. If _empty_, module will take all the columns available in the `header_row`### header_row
**Type**: `[]string`
A row from csv file that you think is a header### clean
**Type**: `bool`
Exclude non-existent columns from the results```go
// clean = false
[ "Name", "NonExistent", "Counter" ], [ 1, -1, 0 ]// clean = true
[ "Name", "Counter" ], [ 1, 0 ]
```## IndexByName()
Returns a column index by it's name. If column does not exists, returns `-1`
```go
i := csvtools.IndexByName(column_name, mapped_list)
```### column_name
**Type**: `string`
Name of the column you are looking for### mapped_list
**Type**: `map[string]int`
A row from csv file that you consider a header