Comments (5)
Working solution
val df = (1..1000).toDataFrame {
"id" from { it }
"value" from {"value$it" }
}
from dataframe.
Need to check - does it have the same behaviour in the Gradle projects
from dataframe.
It works fine in gradle projects, so we'll need to check what weird type inference is going on in the Jupyter integration...
It creates a DataFrame like:
entries | keys | size | values |
---|---|---|---|
[id=1, value=value1] | [id, value] | 2 | [1, value1] |
[id=2, value=value2] | [id, value] | 2 | [2, value2] |
[id=3, value=value3] | [id, value] | 2 | [3, value3] |
[id=4, value=value4] | [id, value] | 2 | [4, value4] |
[id=5, value=value5] | [id, value] | 2 | [5, value5] |
[id=6, value=value6] | [id, value] | 2 | [6, value6] |
[id=7, value=value7] | [id, value] | 2 | [7, value7] |
[id=8, value=value8] | [id, value] | 2 | [8, value8] |
[id=9, value=value9] | [id, value] | 2 | [9, value9] |
[id=10, value=value10] | [id, value] | 2 | [10, value10] |
However, was this the solution you were looking for?
I suspect you want to create a dataframe with a column id
and a column value
right? Then indeed @zaleslaw 's solution works great.
Constructing a DataFrame is usually done by column and not by row, as that's how they're stored in memory. That's why all DataFrame creation methods are built the way they are. If you have a List<Map<String, T>>
and you want each map to be like a row, you could make something like this:
val df = (1..1000).map {
mapOf("id" to it, "value" to "value$it")
}.toDataFrame {
source.map { it["id"] }.toColumn() into "id"
source.map { it["value"] }.toColumn() into "value"
}
If you really have to construct a DataFrame row by row, in theory you could but it would essentially entail making many small DFs and concatenating them, like:
val df = (1..1000).map {
mapOf("id" to it, "value" to "value$it")
}.map {
dataFrameOf(header = it.keys, values = it.values)
}.concat()
from dataframe.
Ah yeah. Good explanation. I just copied some code from ChatGPT as part of testing something else when I saw the crash. So I didn't realize that it did things slightly wrong.
from dataframe.
@cmelchior could we close?
from dataframe.
Related Issues (20)
- `"" + columnRef` becomes `String` HOT 3
- Update kotlinx.datetime version to 0.6.0
- Test `writeJsonStr` is broken and probably is not a part of common suite
- `NullPointerException` using `except` to exclude double nested column HOT 3
- DataFrame fails on simple actions with casting BigInteger to Long HOT 5
- Add a User Guide "How to handle large CSV?"
- Documentation and README lack information about Kotlin Notebook HOT 1
- Documentation for df codegen workflow HOT 1
- Support for KSP2 (for beta K2 compiler exploration) HOT 3
- Integration with ktor-client
- Update `readSQL` documentation for release 0.14
- Move Jupyter integration in new dataframe-jupyter module HOT 3
- Add an actual table of all functions with level of support in Compiler Plugin
- Make ReducedGroupBy implement DataFrame interface
- GroupBy.sort and sortBy vague error reporting
- Embed into the library some widely known dataset to learn better our library
- isOpenApiStr logger leaks to Gradle HOT 2
- Improve and document CSV reading options HOT 3
- Add a migration guide for Pandas developers
- DataFrame with empty column infers type `Any` instead of `Nothing`
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.