Support
Quality
Security
License
Reuse
Coming Soon for all Libraries!
Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Go Module for Tabular Datasets in CSV, JSON, YAML, etc.
Usage
ds := NewDataset([]string{"firstName", "lastName"})
Filtering
ds := NewDataset([]string{"Maker", "Model"})
ds.AppendTagged([]interface{}{"Porsche", "911"}, "fast", "luxury")
ds.AppendTagged([]interface{}{"Skoda", "Octavia"}, "family")
ds.AppendTagged([]interface{}{"Ferrari", "458"}, "fast", "luxury")
ds.AppendValues("Citroen", "Picasso")
ds.AppendValues("Bentley", "Continental")
ds.Tag(4, "luxury") // Bentley
ds.AppendValuesTagged("Aston Martin", "DB9", /* these are tags */ "fast", "luxury")
Sorting
ds := NewDataset([]string{"Maker", "Model", "Year"})
ds.AppendValues("Porsche", "991", 2012)
ds.AppendValues("Skoda", "Octavia", 2011)
ds.AppendValues("Ferrari", "458", 2009)
ds.AppendValues("Citroen", "Picasso II", 2013)
ds.AppendValues("Bentley", "Continental GT", 2003)
sorted, err := ds.Sort("Year").CSV()
fmt.Println(sorted)
// >>
// Maker, Model, Year
// Bentley, Continental GT, 2003
// Ferrari, 458, 2009
// Skoda, Octavia, 2011
// Porsche, 991, 2012
// Citroen, Picasso II, 2013
Constraining
ds := NewDataset([]string{"Maker", "Model", "Year"})
ds.AppendValues("Porsche", "991", 2012)
ds.AppendValues("Skoda", "Octavia", 2011)
ds.AppendValues("Ferrari", "458", 2009)
ds.AppendValues("Citroen", "Picasso II", 2013)
ds.AppendValues("Bentley", "Continental GT", 2003)
ds.ConstrainColumn("Year", func(val interface{}) bool { return val.(int) > 2008 })
ds.ValidFailFast() // false
if !ds.Valid() { // validate the whole dataset, errors are retrieved in Dataset.ValidationErrors
ds.ValidationErrors[0] // Row: 4, Column: 2
}
JSON
ds, _ := LoadJSON([]byte(`[
{"age":90,"firstName":"John","lastName":"Adams"},
{"age":67,"firstName":"George","lastName":"Washington"},
{"age":83,"firstName":"Henry","lastName":"Ford"}
]`))
YAML
ds, _ := LoadYAML([]byte(`- age: 90
firstName: John
lastName: Adams
- age: 67
firstName: George
lastName: Washington
- age: 83
firstName: Henry
lastName: Ford`))
JSON
json, _ := ds.JSON()
fmt.Println(json)
XML
xml, _ := ds.XML()
fmt.Println(xml)
CSV
csv, _ := ds.CSV()
fmt.Println(csv)
TSV
tsv, _ := ds.TSV()
fmt.Println(tsv)
YAML
yaml, _ := ds.YAML()
fmt.Println(yaml)
HTML
html := ds.HTML()
fmt.Println(html)
XLSX
xlsx, _ := ds.XLSX()
fmt.Println(xlsx)
// >>>
// binary content
xlsx.WriteTo(...)
ASCII
ascii := ds.Tabular("grid" /* tablib.TabularGrid */)
fmt.Println(ascii)
Markdown
mkd := ds.Markdown() // or
mkd := ds.Tabular("markdown" /* tablib.TabularMarkdown */)
fmt.Println(mkd)
MySQL
sql := ds.MySQL()
fmt.Println(sql)
Postgres
sql := ds.Postgres()
fmt.Println(sql)
Databooks
db := NewDatabook()
// or loading a JSON content
db, err := LoadDatabookJSON([]byte(`...`))
// or a YAML content
db, err := LoadDatabookYAML([]byte(`...`))
// a dataset of presidents
presidents, _ := LoadJSON([]byte(`[
{"Age":90,"First name":"John","Last name":"Adams"},
{"Age":67,"First name":"George","Last name":"Washington"},
{"Age":83,"First name":"Henry","Last name":"Ford"}
]`))
// a dataset of cars
cars := NewDataset([]string{"Maker", "Model", "Year"})
cars.AppendValues("Porsche", "991", 2012)
cars.AppendValues("Skoda", "Octavia", 2011)
cars.AppendValues("Ferrari", "458", 2009)
cars.AppendValues("Citroen", "Picasso II", 2013)
cars.AppendValues("Bentley", "Continental GT", 2003)
// add the sheets to the Databook
db.AddSheet("Cars", cars.Sort("Year"))
db.AddSheet("Presidents", presidents.SortReverse("Age"))
fmt.Println(db.JSON())
Installation
go get github.com/agrison/go-tablib
QUESTION
Replacing dataframe value given multiple condition from another dataframe with R
Asked 2022-Apr-14 at 16:16I have two dataframes one with the dates (converted in months) of multiple survey replicates for a given grid cell and the other one with snow data for each month for the same grid cell, they have a matching ID column to identify the cells. What I would like to do is to replace in the first dataframe, the one with months of survey replicates, the month value with the snow value for that month considering the grid cell ID. Thank you
CellID <- c(1,2,3,4,5,6)
sampl1 <- c("oct", "oct", "oct", "nov", NA, NA)
sampl2 <- c("nov", "nov", "jan", NA, NA, NA)
sampl3 <- c("dec", "dec", "jan", NA, NA, NA)
df1 <- data.frame(CellID, sampl1, sampl2, sampl3)
print(df1)
CellID <- c(1,2,3,4,5,6)
oct <- c(0.1, 0.1, 0.1, 0.1, 0.1, 0.1)
nov <- c(0.4, 0.5, 0.4, 0.5, 0.6, 0.5)
dec <- c(0.6, 0.7, 0.8, 0.7, 0.6, 0.8)
df2 <- data.frame(CellID, oct, nov, dec)
print(df2)
CellID <- c(1,2,3,4,5,6)
sampl1_snow <- c(0.1, 0.1, 0.1, 0.5, NA, NA)
sampl2_snow <- c(0.4, 0.5, 0.9, NA, NA, NA)
sampl3_snow <- c(0.6, 0.7, 1, NA, NA, NA)
df3 <- data.frame(CellID, sampl1_snow, sampl2_snow, sampl3_snow)
print(df3)
ANSWER
Answered 2022-Apr-14 at 14:50df3 <- df1
df3[!is.na(df1)] <- df2[!is.na(df1)]
# CellID sampl1 sampl2 sampl3
# 1 1 0.1 0.4 0.6
# 2 2 0.1 0.5 0.7
# 3 3 0.1 0.4 0.8
# 4 4 0.1 <NA> <NA>
# 5 5 <NA> <NA> <NA>
# 6 6 <NA> <NA> <NA>
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit