I have a CSV file, please note you should copy and paste it and rename the file name to GPA.csv, and I would like to import that into Mathematica and fit it using a power function.
Note: I am aware that fitting it perfectly with a power function is very undesirable as it gives bad predictions.
So I began by doing the following:
data = Import["C:\\GPA.csv", "Table"]
linfit = Fit[data, {1,x}, x]
Now the strange thing is that it gives me an error stating:
Fit::fitc: Number of coordinates (0) is not equal to the number of variables (1). >>
But I am sure I have entered more than 350 coordinates. What am I doing wrong?
PS: I have also try to do test = Transpose[data], but then I get about 350 coordinates and it is still not equal to the number of variables.
To answer both of your questions:
Import["C:\\GPA.CSV", "Data"] will make everything work - as would simply Import["C:\\GPA.CSV"].
The reason these things are different is because Mathematica has an unintuitive and (IMO) confusingly documented way of importing files. The specific reason "Table" didn't work was that this is being interpreted as the 'file format', and by default - see the format documentation - Import assumes that in this case:
"FieldSeparators" = {" ","\t"}
so that your commas are actually assumed to be part of a string on each line, rather than a separator - only spaces and tabs are allowed. (This is much more confusing if you have a file containing 1, 2 in which case you get one string "1," and one number 2.) As a result, you could also use
Import["C:\\GPA.CSV", "Table", "FieldSeparators" -> ","]
The CSV file format, of course, assumes commas as the separator as you wanted. Confusingly, "Data", in this context, is not a 'file format', but an 'element'. This means that the .csv file extension lets the file be imported as a CSV file, and then you request... wait for it... the 'data' element from the imported file. Which is the data.
You can try reading the Import documentation and the listing of formats but I imagine you already tried.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With