# Upload csv to dataset

**URL:** <https://forum.inductiveautomation.com/t/upload-csv-to-dataset/79797>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 28, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/upload-csv-to-dataset/79797 "2023-09-28T15:15:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Travis\_Opperud](https://avatars.discourse-cdn.com/v4/letter/t/c5a1d2/32.png) [@Travis\_Opperud](https://forum.inductiveautomation.com/u/Travis_Opperud)\
**Post date:** [September 28, 2023, 4:33pm UTC](https://forum.inductiveautomation.com/t/upload-csv-to-dataset/79797/2 "2023-09-28T16:33:19Z")

</div>

Figured it out, Not sure why I got hung up like I did. If anyone else gets stuck: the following class can parse csv files and store as a dataset:

```auto
class CSVParser:
	
	def __init__ (self, file_in):
		self.file = file_in
		self.file_string = file_in.getString()
		self.rows = [row.split(',') for row in self.file_string.split('\r')]
		self.num_cols = max([len(row) for row in self.rows])
		self.num_rows = len(self.rows)
		self.headers = self.rows[0]
		self.data = self.rows[1:]
	
	@property
	def extended_headers(self):
		headers_output = self.headers
		ii = 1
		while len(headers_output) < self.num_cols:
			headers_output.append('Placeholder{}'.format(ii))
			ii += 1
		return headers_output
	
	def extend_row(self, row):
		row_output = row
		while len(row_output) < self.num_cols:
			row_output.append(None)
		return row_output
	
	@property
	def dataset(self):
		headers = self.extended_headers
		data = [self.extend_row(row) for row in self.data]
		return system.dataset.toDataSet(headers, data)

```

On fileUpload script:

```auto
system.perspective.print('file received')
parser = parsers.CSVParser(event.file)
	
self.getSibling("Table").props.data = parser.dataset

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/upload-csv-to-dataset/79797)._
