# \[?\] Plot data from csv file?

**URL:** <https://community.wolfram.com/t/plot-data-from-csv-file/10677>\
**Category:** Questions\
**Tags:** graphics-and-visualization, import-and-export\
**Created:** [June 9, 2017, 7:26am UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677 "2017-06-09T07:26:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![riccardomoro6](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@riccardomoro6](https://community.wolfram.com/u/riccardomoro6)\
**Post date:** [June 9, 2017, 7:26am UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/1 "2017-06-09T07:26:07Z")

</div>

Hi i have a problem i can’t plot numbers which are contained in a table in this form, i have imported this data from a csv file:

```
{
 {"101	-0.377"},
 {"101.02	-0.407"},
 {"101.04	-0.419"},
 {"101.06	-0.434"}
}

```

i want to make a a graphic where in x there is the first column and in y the second, i’ve tried several ways and i didn’t succeded on it.  
Thanks for answering. I put the file below.

---

<div class="post-metadata">

**Author:** ![girishav](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/girishav/32/28159_2.png) [@girishav](https://community.wolfram.com/u/girishav)\
**Post date:** [June 9, 2017, 8:02am UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/2 "2017-06-09T08:02:30Z")

</div>

Import the CSV file data values as numeric [In your notebook they have been imported as strings] :

```
Import["C:\\Users\\User\\Desktop\\Prova3.csv", "Numeric" -> True]

```

Or use [SemanticImport](https://reference.wolfram.com/language/ref/SemanticImport.html) command. Please check the documentation for more information.

Alternatively, you can still plot the values in your notebook:

```
ListPlot@ToExpression[Flatten[#, 1] & /@ (StringSplit /@ lalla)]

```

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [June 9, 2017, 8:18am UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/3 "2017-06-09T08:18:37Z")

</div>

Try this:

```
ToExpression /@ StringSplit[StringJoin[Characters[#] /. "\t" -> ","], ","] & /@ lalla;
ListPlot[%]

```

---

<div class="post-metadata">

**Author:** ![riccardomoro6](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@riccardomoro6](https://community.wolfram.com/u/riccardomoro6)\
**Post date:** [June 9, 2017, 8:36am UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/4 "2017-06-09T08:36:09Z")

</div>

Thanks a lot, you have saved me!!

---

<div class="post-metadata">

**Author:** ![riccardomoro6](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@riccardomoro6](https://community.wolfram.com/u/riccardomoro6)\
**Post date:** [June 10, 2017, 11:09am UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/5 "2017-06-10T11:09:35Z")

</div>

I have an another problems with NonLinearRegression  
Forgive my ignorance but i don’t understand why the program doesn’t fit my data, the number problem was fixed, but mathematica says that the list of numbers is not a list and it can’t do the fit. I put below the program to see better what i mean.

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [June 10, 2017, 11:42am UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/6 "2017-06-10T11:42:45Z")

</div>

your data is in the form of a list of a list of data points. you need to remove the outer list:

you have:

```
{{{1,1},{2,2}}}

```

you need to have:

```
{{1,1},{2,2}}

```

take the first element of data (which is the list you want):

```
NonlinearModelFit[data[[1]],....]

```

---

<div class="post-metadata">

**Author:** ![riccardomoro6](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@riccardomoro6](https://community.wolfram.com/u/riccardomoro6)\
**Post date:** [June 10, 2017, 12:18pm UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/7 "2017-06-10T12:18:40Z")

</div>

It gives me this error: **Part::partd: Part specification data[[1]] is longer than depth of object**.

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [June 11, 2017, 2:59am UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/8 "2017-06-11T02:59:41Z")

</div>

you must have a typo (or data is undefined). Here is your file – since I do not have your data file, I skipped that step. Your fit is numerically unstable because you will get stuck in local minima – you can check the RSquared and adjust the starting value for b to get a different minimum. You get an answer if you start the frequency reasonably close to the “correct” answer.

I hope this helps

---

<div class="post-metadata">

**Author:** ![riccardomoro6](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@riccardomoro6](https://community.wolfram.com/u/riccardomoro6)\
**Post date:** [June 11, 2017, 3:10pm UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/9 "2017-06-11T15:10:27Z")

</div>

Ok i’ve understood the passages, thank a lot for the attention you are giving to me.  
If you can explain how to get data in order it would be wonderful. I add the file with numbers.  
Thanks again

---

<div class="post-metadata">

**Author:** ![riccardomoro6](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@riccardomoro6](https://community.wolfram.com/u/riccardomoro6)\
**Post date:** [June 11, 2017, 3:22pm UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/10 "2017-06-11T15:22:45Z")

</div>

I don’t understand why did you put six in this line  
**nlm = NonlinearModelFit[ndat, a_Sin[b_x + c], {a, {b, 6}, c}, x]**

---

<div class="post-metadata">

**Author:** ![riccardomoro6](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@riccardomoro6](https://community.wolfram.com/u/riccardomoro6)\
**Post date:** [June 11, 2017, 3:42pm UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/11 "2017-06-11T15:42:57Z")

</div>

ok i succeded on doing the fit thanks a lot!! can you only explain now why did you put the six inside nonlinearmodelfit?  
I can now do the relation Thank!!

---

<div class="post-metadata">

**Author:** ![riccardomoro6](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@riccardomoro6](https://community.wolfram.com/u/riccardomoro6)\
**Post date:** [June 11, 2017, 3:45pm UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/12 "2017-06-11T15:45:19Z")

</div>

Ok no i didn’t succeded sorry:(  
can you explain how to get data in order please

---

<div class="post-metadata">

**Author:** ![neils](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/neils/32/20595_2.png) [@neils](https://community.wolfram.com/u/neils)\
**Post date:** [June 11, 2017, 7:21pm UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/13 "2017-06-11T19:21:11Z")

</div>

here is the file with more comments showing how to get the data.

The 6 is a starting value for the variable “b”. if you leave out starting values they all start at 0. When you do that, the fit gets stuck at a local minimum which is not very good. If you start it at 5 or 6 you get the best fit.

Study the file and look at the documentation.

---

<div class="post-metadata">

**Author:** ![riccardomoro6](https://avatars.discourse-cdn.com/v4/letter/r/e68b1a/32.png) [@riccardomoro6](https://community.wolfram.com/u/riccardomoro6)\
**Post date:** [June 12, 2017, 9:41am UTC](https://community.wolfram.com/t/plot-data-from-csv-file/10677/14 "2017-06-12T09:41:58Z")

</div>

Thanks a lot, really.
