# CSV Read Error - ValueError: CSV invalid format: expected #NAMES on line 1

**URL:** <https://forum.inductiveautomation.com/t/csv-read-error-valueerror-csv-invalid-format-expected-names-on-line-1/41695>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [December 21, 2020, 5:37pm UTC](https://forum.inductiveautomation.com/t/csv-read-error-valueerror-csv-invalid-format-expected-names-on-line-1/41695 "2020-12-21T17:37:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 21, 2020, 5:37pm UTC](https://forum.inductiveautomation.com/t/csv-read-error-valueerror-csv-invalid-format-expected-names-on-line-1/41695/1 "2020-12-21T17:37:19Z")

</div>

Trying to read a CSV file to do some logic on it in the designer scripting console. I have this as my script -

```auto
csv_path = "C:\\Users\\bkarabinchak\\Desktop\\toRead.csv"
csv_string = system.file.readFileAsString(csv_path)
csv_file = system.dataset.fromCSV(csv_string)

```

and am getting the following error

```auto
Traceback (most recent call last):
  File "<input>", line 3, in <module>
ValueError: CSV invalid format: expected #NAMES on line 1

```

Here is my CSV file which seems very run of the mill so I am not sure what is going wrong - [toRead.csv](https://forum.inductiveautomation.com/uploads/short-url/zCiXyRO02ifH2ESS9ngkvKwoIgm.csv) (2.0 KB)

How can I read this csv file?

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [December 21, 2020, 5:51pm UTC](https://forum.inductiveautomation.com/t/csv-read-error-valueerror-csv-invalid-format-expected-names-on-line-1/41695/2 "2020-12-21T17:51:28Z")

</div>

Your CSV is not formatted correctly for system.dataset.fromCSV().

Here's the format:  
[https://docs.inductiveautomation.com/display/DOC81/system.dataset.fromCSV](https://docs.inductiveautomation.com/display/DOC81/system.dataset.fromCSV)

> **[system.dataset.fromCSV | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-dataset/system-dataset-fromCSV)**
>
> Converts a dataset stored in a CSV formatted string to a dataset that can be immediately assignable to a dataset property in your project.

_edit_: updated doc link.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 21, 2020, 5:55pm UTC](https://forum.inductiveautomation.com/t/csv-read-error-valueerror-csv-invalid-format-expected-names-on-line-1/41695/3 "2020-12-21T17:55:25Z")

</div>

Boy do I have egg on my face telling my coworkers to read the documentation for problems and missing this one. Thanks.

---

<div class="post-metadata">

**Author:** ![Grzegorz\_Burak](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@Grzegorz\_Burak](https://forum.inductiveautomation.com/u/Grzegorz_Burak)\
**Post date:** [June 30, 2023, 2:43pm UTC](https://forum.inductiveautomation.com/t/csv-read-error-valueerror-csv-invalid-format-expected-names-on-line-1/41695/4 "2023-06-30T14:43:06Z")

</div>

Hello

I have tried to import CSV data into Ignition but it has problem with CSV file. I have checked example below and nothing.  
https://docs.inductiveautomation.com/display/DOC81/system.dataset.fromCSV

I copied almost everything from both script and file content from the example mentioned before and it still says CSV is not formatted properly.

My script:

> # In this example it is assumed that the CSV file being read was a dataset
> 
> #that was previously exported using system.dataset.toCSV with the forExport flag set to True:
> 
> # Specify file path.
> 
> file\_path = "C:\VMs\alarms.csv"
> 
> # Read in the file as a string.
> 
> data\_string = system.file.readFileAsString(file\_path)
> 
> # Convert the string to a dataset and store in a variable.
> 
> data = system.dataset.fromCSV(data\_string)
> 
> # Assign the dataset to a table.
> 
> event.source.parent.getComponent('Table').data = data

My CSV:

> #NAMES  
> Col 1,Col 2,Col 3  
> #TYPES  
> I,str,D  
> #ROWS,6  
> 44,Test Row 2,1.8713151369491254  
> 86,Test Row 3,97.4913421614675  
> 0,Test Row 8,20.39722542161364  
> 78,Test Row 9,34.57127071614745  
> 20,Test Row 10,76.41114659745085  
> 21,Test Row 13,13.880548366871926

Result:

> Traceback (most recent call last):  
> File "event:actionPerformed", line 8, in   
> ValueError: CSV invalid format: expected #NAMES on line 1
> 
> Ignition v8.1.26 (b2023032308)  
> Java: Azul Systems, Inc. 11.0.18

Can you help me?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [July 24, 2023, 8:33am UTC](https://forum.inductiveautomation.com/t/csv-read-error-valueerror-csv-invalid-format-expected-names-on-line-1/41695/5 "2023-07-24T08:33:13Z")

</div>

> [@Grzegorz\_Burak](#):
>
> Can you help me?

This script worked perfectly for me on the test data using a button:

```auto
filePath = "C:/myPath/testFile.csv"
dataString = system.file.readFileAsString(filePath)
data = system.dataset.fromCSV(dataString)
event.source.parent.getComponent('Power Table').data = data

```

**Result:**  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/9/69f471c3f4424034ca91e04e8b954094fe11dfdf.png)

In case it helps, here is the test file I used:  
[testFile.csv](https://forum.inductiveautomation.com/uploads/short-url/q7pufL6x3ecq60oZsjYklPuIpDD.csv) (241 Bytes)
