These are chat archives for nrinaudo/kantan.csv

29th
Sep 2017
olivetechnologies
@olivetechnologies
Sep 29 2017 14:09
Hello @nrinaudo Hope you are doing great today

import kantan.csv._
import kantan.csv.ops._
import kantan.csv.generic._
import scala.io.Source._


final case class CardData(Time: Int, V1: Double, V2: Double, V3: Double, V4: Double, V5: Double, V6: Double,
                          V7: Double, V8: Double,V9: Double,V10: Double,V11: Double,V12: Double, V13: Double, V14: Double,
                          V15: Double,V16: Double, V17: Double,V18: Double,V19: Double, V20: Double, V21: Double, V22: Double,
                          V23: Double,V24: Double, V25: Double, V26: Double, V27: Double, V28: Double, Amount:Double, Class: Int)

object CreditCard {

   def main(args: Array[String]): Unit = {
    val rawData1 = fromFile("C:\\Users\\CHRISTIANAH .O\\IdeaProjects\\creditcard.csv").mkString
    val caseCreditCard = rawData1.asCsvReader[CardData](rfc.withHeader).toArray

     caseCreditCard.take(5).foreach(println)
  }
}
The above code snippet works well and produces this:
Success(CardData(0,-1.359807134,-0.072781173,2.536346738,1.378155224,-0.33832077,0.462387778,0.239598554,0.098697901,0.36378697,0.090794172,-0.551599533,-0.617800856,-0.991389847,-0.311169354,1.468176972,-0.470400525,0.207971242,0.02579058,0.40399296,0.251412098,-0.018306778,0.277837576,-0.11047391,0.066928075,0.128539358,-0.189114844,0.133558377,-0.021053053,149.62,0))
Success(CardData(0,1.191857111,0.266150712,0.166480113,0.448154078,0.060017649,-0.082360809,-0.078802983,0.085101655,-0.255425128,-0.166974414,1.612726661,1.065235311,0.489095016,-0.143772296,0.635558093,0.463917041,-0.114804663,-0.18336127,-0.145783041,-0.069083135,-0.225775248,-0.638671953,0.101288021,-0.339846476,0.167170404,0.125894532,-0.008983099,0.014724169,2.69,0))
Success(CardData(1,-1.358354062,-1.340163075,1.773209343,0.379779593,-0.503198133,1.800499381,0.791460956,0.247675787,-1.514654323,0.207642865,0.624501459,0.066083685,0.717292731,-0.165945923,2.345864949,-2.890083194,1.109969379,-0.121359313,-2.261857095,0.524979725,0.247998153,0.771679402,0.909412262,-0.689280956,-0.327641834,-0.139096572,-0.055352794,-0.059751841,378.66,0))
Success(CardData(1,-0.966271712,-0.185226008,1.79299334,-0.863291275,-0.01030888,1.247203168,0.23760894,0.377435875,-1.387024063,-0.054951922,-0.226487264,0.178228226,0.50775687,-0.287923745,-0.631418118,-1.059647245,-0.684092786,1.965775003,-1.23262197,-0.208037781,-0.108300452,0.005273597,-0.190320519,-1.175575332,0.647376035,-0.221928844,0.062722849,0.061457629,123.5,0))
Success(CardData(2,-1.158233093,0.877736755,1.548717847,0.403033934,-0.407193377,0.095921462,0.592940745,-0.270532677,0.817739308,0.753074432,-0.822842878,0.53819555,1.345851593,-1.119669835,0.17512113,-0.451449183,-0.237033239,-0.038194787,0.803486925,0.40854236,-0.009430697,0.798278495,-0.13745808,0.141266984,-0.206009588,0.502292224,0.21942223,0.215153147,69.99,0))
olivetechnologies
@olivetechnologies
Sep 29 2017 14:23
This below code :
object CreditCard {

   def main(args: Array[String]): Unit = {
    val rawData1 = fromFile("C:\\Users\\CHRISTIANAH .O\\IdeaProjects\\creditcard.csv").mkString
    val caseCreditCard = rawData1.asCsvReader[CardData](rfc.withHeader).toArray

   val maxV1 = caseCreditCard.map(_.V1).max; println(maxV1)
  }
}
Produces this error:
Error:(20, 37) value V1 is not a member of kantan.csv.ReadResult[KantanReadCsv.CardData]
   val maxV1 = caseCreditCard.map(_.V1).max; println(maxV1)
My question now is how do i access each value or column from each CardData case class produced after parsing the data
Nicolas Rinaudo
@nrinaudo
Sep 29 2017 14:26
I'm not sure what to tell you. ReadResult does not have a V1 field, that's perfectly correct. The problem is not to do with kantan.csv, but with your code. If you don't want a ReadResult, I suggest you read the documentation on that type to see whether there is any combinator to help you
olivetechnologies
@olivetechnologies
Sep 29 2017 14:26
as passed above
Nicolas Rinaudo
@nrinaudo
Sep 29 2017 14:27
at some point, helping you understand your tools, your code, and the scala language, on top of being counterproductive (you'll never learn if you don't work this stuff out for yourself), is just going to take too much time. This channel is here to help with kantan.csv, and none of your issues so far have been with kantan.csv, or they would have been fixed in minutes if you'd read the documentation.
olivetechnologies
@olivetechnologies
Sep 29 2017 14:31
    val caseCreditCard = rawData1.asCsvReader[CardData](rfc.withHeader).toArray

   val maxV1 = caseCreditCard.map(_.V1).max; println(maxV1)
I know ReadResult do not have V1 but from the code above caseCreditCard is an array of CardData case classes.
Nicolas Rinaudo
@nrinaudo
Sep 29 2017 14:31
IntelliJ shows you the types. Use it. caseCreditCard is not an Array[CarData].
think things though. If it was an Array[CardData], then the compiler wouldn't complain that it's not.

if you get stuck at some point, I mean really stuck, I'm happy to help. But right now, you've not even looked at the type of the data you're working with.

I'm happy to help. I'm not happy to do your job for you.

olivetechnologies
@olivetechnologies
Sep 29 2017 14:34
i actually put toArray to convert it to Array
Nicolas Rinaudo
@nrinaudo
Sep 29 2017 14:34
I know. It's an array of something, just not of CardData.
check. the. types.
dont' guess them. Please. I don't have much time to allocate to my OSS projects and you've been eating all of it recently, for basic stuff that you really should learn by yourself if you want to do some Scala.
you have types. Read them.
olivetechnologies
@olivetechnologies
Sep 29 2017 14:35
Don't be offended. I guess am getting on your nerves.
Nicolas Rinaudo
@nrinaudo
Sep 29 2017 14:36
You are. You're acting, whether you want to or not, as if my time was at your disposal

it might be a language issue, it might be a cultural issue, in which case I apologise for getting annoyed. But I would prefer if you worked things out for yourself before you ask me for help for the most basic stuff.

The fact that your name looks very much like a company's name is really dodgy as well, it's making me feel like a company is using me as free consulting. I would have thought that providing you tools for free was enough.

olivetechnologies
@olivetechnologies
Sep 29 2017 14:37
It was not intentional of course. I really appreciate your time.
I am an individual.
It's not a company.