# Need help keeping column amount Fixed with import using csv reader

**URL:** <https://forum.inductiveautomation.com/t/need-help-keeping-column-amount-fixed-with-import-using-csv-reader/83168>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [December 14, 2023, 8:48pm UTC](https://forum.inductiveautomation.com/t/need-help-keeping-column-amount-fixed-with-import-using-csv-reader/83168 "2023-12-14T20:48:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IgnitionNewbie](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@IgnitionNewbie](https://forum.inductiveautomation.com/u/IgnitionNewbie)\
**Post date:** [December 14, 2023, 8:48pm UTC](https://forum.inductiveautomation.com/t/need-help-keeping-column-amount-fixed-with-import-using-csv-reader/83168/1 "2023-12-14T20:48:16Z")

</div>

I am using this script mishmashed from posts on this forum/IA's csv info page , and it almost works the way I need it too , but I need help with how its imported

```auto
	##importing from 2 libraries
	from StringIO import StringIO
	import csv
	grabbedfile = event.file.getString("UTF-8")
	Headers = ["Feature","X","Y","Z","i","j","k","DIA"]
	#this is the empty list    
	CsvData = []
	#this is the grabbed file stored in strings in lists , per row
	StringLists = [row for row in csv.reader(StringIO(grabbedfile))] 
	
	for inner_list in StringLists:
	    for element in inner_list:
	    	#put it in the empty list
	        CsvData.append(element)
	        
	#this prints the list as a whole
	#system.perspective.print(CsvData)
	
	#split into groups of 8
	ListGroups = zip(*(iter(CsvData),) * 8)
	#system.perspective.print(ListGroups)
	
	tagpath = "CSVData" ##tag I am putting the data in
	ds = system.dataset.toDataSet(Headers,ListGroups) 
	system.tag.writeBlocking(tagpath,ds)## this line is shoving all the data into the above tag	

	FileNametagpath = "FileName" ##tag I am putting the data in
	FileName = event.file.name
	system.tag.writeBlocking(FileNametagpath,FileName)
	

```

the problem I am having is that the CSVs I am importing from a machine are in a weird format

the columns will look like

```auto
Name,1,2,3,4,5,6,(Blank)
Name,1,2,3,4,5,6,(Blank)
Name,1,2,3,4,5,6,(Blank)
Name,1,2,3,4,5,6,(Blank)
Name,1,2,3,4,5,6,7
Name,1,2,3,4,5,6,(Blank)
Name,1,2,3,4,5,6,(Blank)
Name,1,2,3,4,5,6,7

```

because the 8th column doesnt have any values in it until later on , everytime I import it offsets all of the values from the next rows and starts making a mess out of the system going on afterwards

I have been getting around this by just entering any value into the first row and the 8th column in the csv before I import it , but it would be nicer if I could just drag and drop the CSVs without having to do this everytime. Is there anyway to make it act like there is 8 columns even if the first row only has 7 values?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 14, 2023, 9:05pm UTC](https://forum.inductiveautomation.com/t/need-help-keeping-column-amount-fixed-with-import-using-csv-reader/83168/2 "2023-12-14T21:05:10Z")

</div>

Can you give a sample file?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [December 14, 2023, 9:29pm UTC](https://forum.inductiveautomation.com/t/need-help-keeping-column-amount-fixed-with-import-using-csv-reader/83168/3 "2023-12-14T21:29:24Z")

</div>

nvm. Try:

`StringLists = [(row+([None]*8))[:8] for row in csv.reader(StringIO(grabbedfile))]`

This should force all rows to 8 elements
