from itertools import islice import csv filename = "CFSpring2018Employers.csv" #I assigned the file to a variable f = open(filename) #I couldn't leave it default due to UTF-8 error from orginial reader = csv.reader(f) f.close #Dictionary for part 1 'Companies' companies = {} countComp = 0 #Sets the 'rows to 0 for row in reader: #reader has assigned value to read csv info if row[0] == 'Company': #Searches row called 'Company' for item in row: companies[countComp] = item #Everytime it shows it puts it into the dictionary countComp += 1 break for i in companies: #Allows me to print numbers next to the companies dict print(i, companies[i]) ReadyColumn = [] #Making a new list for cleaned up data NumCow = 0 for row in reader: NumCow +=1 if NumCow > 0 and NumCow < 31 and row[0] != '': #This will read the rows between 0-31, and if the row contains 'Nothing' it skips ReadyColumn.append(row) #Updates the list rowNum = -1 #Resets the counter for row in ReadyColumn: rowNum += 1 print(rowNum, ','.join(row)) #Joins any weird marks and prints as desired output data_employer = {'No', 'Column', 'Sum'} for vari in range(14): sum = 0 for row in ReadyColumn: if row[vari] != '': sum =+1 cleaner_employer = (companies[vari], sum) for i in data_employer: print(i, data_employer,i[0], data_employer,i[1])
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question