Comments (7)
https://godoc.org/github.com/rocketlaunchr/dataframe-go#Apply
https://godoc.org/github.com/rocketlaunchr/dataframe-go#ApplyDataFrameFn
from dataframe-go.
var ctx = context.Background()
func main() {
csvStr := `contact_number_country_code,contact_number
"973","12345678"`
df, _ := imports.LoadFromCSV(ctx, strings.NewReader(csvStr), imports.CSVLoadOptions{
DictateDataType: map[string]interface{}{
"contact_number_country_code": "",
"contact_number": "",
},
})
sConcatContactNumber := dataframe.NewSeriesString("concat_contact_number", &dataframe.SeriesInit{Size: df.NRows()})
df.AddSeries(sConcatContactNumber, nil)
applyFn := dataframe.ApplyDataFrameFn(func(vals map[interface{}]interface{}, row, nRows int) map[interface{}]interface{} {
return map[interface{}]interface{}{
"concat_contact_number": vals["contact_number_country_code"].(string) + vals["contact_number"].(string),
}
})
_, err := dataframe.Apply(ctx, df, applyFn, dataframe.FilterOptions{InPlace: true})
if err != nil {
log.WithError(err).Error("concatenation cannot be applied")
}
fmt.Println(df)
}
from dataframe-go.
Can you try the sample I wrote above.
The issue is when you return the vals
. The return map indicates what you want to change.
The key of map accepts ints (for index of Series) or strings (for name of series).
In your erroneous case:
vals: map[0:973 1:12345678 2:<nil> concat_contact_number:97312345678 contact_number:12345678 contact_number_country_code:973]
It is saying change second column to nil but also saying change concat_contact_number Series to "97312345678". They point to the same Series in your case.
Either use ints or strings when referring to Series but not both.
from dataframe-go.
@pjebs I updated my code to return a new map from inside ApplyDataFrameFn
and it now works. Thank you.
I have several questions so I may understand better how this library works:
-
I'm not sure where in my code where the int or string keys were set. From what I understand I did not explicitly set to use the int or string keys. The
vals
map that was received byApplyDataFrameFn
already contained both. Can you point me where it was set? -
The key difference that I saw between your implementation and mine is that you created a new map inside the
ApplyDataFrameFn
instead of directly modifying thevals
map. Is this the recommended way?
from dataframe-go.
-
the
vals
param contains the existing values for the row with the key as an int (index) and string (name) for convenience. -
The applyFn must return a map that contains only what you want to update. You were basically rereturning the current row values (and not just the changes to update). I have updated the documentation to make it clearer.
from dataframe-go.
Thank you @pjebs much clearer now. Do you have a link to the said documentation?
from dataframe-go.
let me refresh godocs.org
from dataframe-go.
Related Issues (20)
- undefined: dataframe.LoadFromCSV HOT 5
- Reading from Parquet HOT 11
- Export to Parquet example HOT 1
- Draw graphs from columns of dataframe HOT 9
- Appending a dataframe with another one. HOT 1
- How to set_index with two columns? HOT 2
- LoadFromJSON Not Working HOT 8
- How to remove duplicate rows in DataFrame? HOT 1
- Problem getting the package HOT 4
- is group by supported? HOT 1
- Bad import, was an upstream dependency deleted? HOT 5
- Error to read parquet with latest parquet-go HOT 21
- Error to read csv encoding utf-8 with bom and export back to parquet HOT 28
- Indirect dependency `github.com/blend/go-sdk v1.1.1` does not exist HOT 6
- Error to import csv, raised parquet-go error HOT 4
- Progress for re-write of dataframe-go? HOT 14
- DF Practice
- Add equivalent of `pandas`.`read_html`
- how to achieve multi index ?
- This library is defunct: please prove me wrong
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dataframe-go.