• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

How to add a List<Double> to a dataframe?

 
Ranch Hand
Posts: 74
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using the Smile library and I'm trying to figure out if there is a way to add a List<Double> to an existing dataframe or to make a new one that I can then merge into the old one.

I've searched through the javadoc but I haven't really found anything to do it.

I'm thinking maybe I can add the List<Double> to a text file and then read the text file using Read.csv(TextFIle, format); into a dataframe and then merge it using .merge() but I feel like this would end up being very repetitious and add a lot of unnecessary text files.

So I'm wondering if there is a better way to go about this?

Thanks so much!
 
Saloon Keeper
Posts: 4164
160
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can first create a DoubleVector with a static method from the interface DoubleVector, something like:

Then use the dataframe's merge method. See the API.

A little snag: the list.stream() will result in a Stream<Double>, so you must convert that to a DoubleStream.
 
Piet Souris
Saloon Keeper
Posts: 4164
160
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to mention that "merge" creates a new DataFrame. The original frame remains unchanged.
 
Glenda Karen
Ranch Hand
Posts: 74
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much!! This worked amazingly!

I converted the Stream<Double>:
 
Piet Souris
Saloon Keeper
Posts: 4164
160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.

I always use, for brevity reasons,
 
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic