Home How do I get my loop to add up the right amount of tally
Reply: 0

How do I get my loop to add up the right amount of tally

user11835
1#
user11835 Published in May 21, 2018, 3:03 am

I am having issues that I can't seem to add up the correct info from my csv file that I am supposed to use. I need to 'tally' the total amount of objects from the csv file in the proper columns.

No Column Sum 0 Company 28 1 Booth 28 2 Full-Time 25 3 Full-Time Visa Sponsor 5 4 Part-Time 1 5 Internship 18 6 Freshman 7 7 Sophomore 9 8 Junior 17 9 Senior 24 10 Post-Bacs 17 11 MS 17 12 PhD 6 13 Alumni 15

That is the correct output, however I am getting

0 Column Sum 1 Company 27 2 Booth 27 3 Full-Time 27 4 Full-Time Visa Sponsor 27 5 Part-Time 27 6 Internship 27 7 Freshman 27 8 Sophomore 27 9 Junior 27 10 Senior 27 11 Post-Bacs 27 12 MS 27 13 PhD 27

I think it's the use of my dictionary. Here is my following code, and csv file posted under that.

import csv                                  #Allows you to import or export spreadsheets
filename = "Spring.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)                      #The reader allows you to pull data from the CSV

                                            #I made a dictonary of the problem stated
company_dict = {0:"Company", 1:"Booth",
                2:"Full-Time", 3:"Full-Time Visa Sponsor",
                4:"Part-Time", 5:"Internship",
                6:"Freshman", 7:"Sophomore",
                8:"Junior", 9:"Senior",
                10:"Post-Bacs", 11:"MS",
                12:"PhD", 13:"Alumni"}

                                            #Loop to organize the company_dict
for lines in company_dict:
    print(repr(lines),company_dict[lines])

keywords = ("AIG","Baylor","CGG","Citi","ExxonMobil","Flow-Cal Inc.",                   #I used a list to help me get the information I wanted from the csv file
           "Global SHop Solutions","Harris Count CTS","HCSS",
           "Hitachi Consulting", "HP Inc.","INT Inc.","JPMorgan Chase & Co",
           "Leidos","McKesson","MRE Consulting Ltd.","NetIQ","PROS",
           "San Jacinto College","SAS","Smartbridge","Sogeti USA",
           "Southwest Research Institute","The Reynolds and Reynolds Company",
           "UH Enterprise Systems","U.S. Marine Corps","ValuD Consuting LLC","Wipro")

DataList = []                                                                           #I made a blank list
with f as filterf:                                                                      #This loop will look for the keywords in the file, and only add those keywords
    output_line_counter = 0                                                             #I needed it to print with rows, so I set it to 0
    for line in filterf:
        if any(keyword in line for keyword in keywords):                                #The actual code that looks for keywords in the line in my file
            output_line_counter += 1                                                    #Adds the column (might not be necessary but it works for me)
            DataList.append(line)

CleanerData = sorted(set(DataList))                                                     #I made a new 'cleaner' list so that it would be alphabetically without spaces
line_counter = 0
for i in CleanerData:                                                                   #I had to do another loop to add rows again, it now prints what is required in the question
    line_counter += 1
    print(line_counter, i, end='')

DataList2 = []
data_employer = {'No': ('Column', 'Sum')}
for empdata in range(14):
    sum = 0
    for i in CleanerData:
        if i[empdata] != '':
            sum += 1
    data_employer[empdata] = (company_dict[empdata], sum)
for k in data_employer:
    print(list(data_employer.keys()).index(k), data_employer[k][0], data_employer[k][1])

Here is my csv file information

ALPHABETICAL ORDER,,,,,,,,,,,,,
,,Positions,,,,Classifications,,,,,,,
Company,Booth,Full-Time,"Full-Time Visa Sponsor",Part-Time,Internship,Freshman,Sophomore,Junior,Senior,Post-Bacs,MS,PhD,Alumni
AIG,10,,,,Yes,,,Jr,,,MS,,
Baylor College of Medicine,19,Yes,Yes,,,,,,,,,,Recent
CGG,17,Yes,Yes,,,,,,,,MS,PhD,Recent
Citi,27/28,Yes,,,Yes,,,Jr,Sr,,,,
ExxonMobil,11,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,,,
,...
Flow-Cal Inc.,16,Yes,,,Yes,,,Jr,Sr,,,,All
Global Shop Solutions,18,Yes,,,Yes,,,,Sr,PB,,,All
Harris County CTS,22,Yes,,,Yes,,,Jr,Sr,PB,MS,PhD,All
HCSS,29,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,MS,,Recent
Hitachi Consulting,13,Yes,,,,,,,Sr,,MS,,
HP Inc.,1,Yes,,,Yes,,,Jr,,,MS,,Recent
INT Inc.,20,Yes,Yes,,Yes,,,Jr,Sr,,MS,PhD,
JPMorgan Chase & Co,3,Yes,,,Yes,,,Jr,Sr,,,,
Leidos,390,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,MS,,
McKesson,26,Yes,,,,,,,Sr,,,,
,,,,,,,,,,,,,
MRE Consulting Ltd.,2,Yes,,,,,,,Sr,PB,MS,,All
NetIQ,7,,,,Yes,,Soph,Jr,Sr,PB,,,
PROS,21,Yes,,,,,,,Sr,,MS,PhD,All
San Jacinto College  ,14,,,,Yes,,Soph,Jr,Sr,PB,MS,,
SAS,4,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,MS,,Recent
Smartbridge,8,Yes,,,,,,,Sr,PB,MS,,
Sogeti USA,15,Yes,,,,,,,Sr,PB,MS,,
Southwest Research Institute,12,Yes,,,Yes,,,Jr,Sr,PB,MS,PhD,All
The Reynolds and Reynolds Company,23,Yes,Yes,,Yes,Fr,Soph,Jr,Sr,PB,,,All
UH Enterprise Systems,9,Yes,Yes,Yes,Yes,Fr,Soph,Jr,Sr,PB,MS,PhD,All
U.S. Marine Corps,25,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,MS,,All
ValuD Consuting LLC,5,Yes,,,,,,,Sr,PB,,,All
Wipro,24,Yes,,,,,,,Sr,PB,,,
BOOTH ORDER,,,,,,,,,,,,,
,Booth,Positions,,,,Classifications,,,,,,,
Company,#,Full-Time,"Full-Time
Visa Sponsor",Part-Time,Internship,Freshman,Sophomore,Junior,Senior,Post-Bacs,MS,PhD,Alumni
HP�Inc.,1,Yes,,,Yes,,,Jr,,,MS,,Recent
"MRE Consulting, Ltd.",2,Yes,,,,,,,Sr,PB,MS,,All
JPMorgan Chase & Co,3,Yes,,,Yes,,,Jr,Sr,,,,
SAS,4,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,MS,,Recent
ValuD Consuting LLC,5,Yes,,,,,,,Sr,PB,,,All
NetIQ,7,,,,Yes,,Soph,Jr,Sr,PB,,,
Smartbridge,8,Yes,,,,,,,Sr,PB,MS,,
UH Enterprise Systems,9,Yes,Yes,Yes,Yes,Fr,Soph,Jr,Sr,PB,MS,PhD,All
AIG,10,,,,Yes,,,Jr,,,MS,,
ExxonMobil,11,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,,,
Southwest Research Institute,12,Yes,,,Yes,,,Jr,Sr,PB,MS,PhD,All
Hitachi Consulting,13,Yes,,,,,,,Sr,,MS,,
San Jacinto College  ,14,,,,Yes,,Soph,Jr,Sr,PB,MS,,
Sogeti USA,15,Yes,,,,,,,Sr,PB,MS,,
"Flow-Cal, Inc.",16,Yes,,,Yes,,,Jr,Sr,,,,All
CGG,17,Yes,Yes,,,,,,,,MS,PhD,Recent
Global Shop Solutions,18,Yes,,,Yes,,,,Sr,PB,,,All
Baylor College of Medicine,19,Yes,Yes,,,,,,,,,,Recent
"INT, Inc.",20,Yes,Yes,,Yes,,,Jr,Sr,,MS,PhD,
PROS,21,Yes,,,,,,,Sr,,MS,PhD,All
Harris County CTS,22,Yes,,,Yes,,,Jr,Sr,PB,MS,PhD,All
The Reynolds and Reynolds Company,23,Yes,Yes,,Yes,Fr,Soph,Jr,Sr,PB,,,All
Wipro,24,Yes,,,,,,,Sr,PB,,,
U.S. Marine Corps,25,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,MS,,All
McKesson,26,Yes,,,,,,,Sr,,,,
Citi,27/28,Yes,,,Yes,,,Jr,Sr,,,,
HCSS,29,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,MS,,Recent
Leidos,30,Yes,,,Yes,Fr,Soph,Jr,Sr,PB,MS,,

This is copy pasted from the csv file in excel.

ALPHABETICAL ORDER                                                  
        Positions               Classifications                         
Company Booth   Full-Time   Full-Time Visa Sponsor  Part-Time   Internship  Freshman    Sophomore   Junior  Senior  Post-Bacs   MS  PhD Alumni
AIG 10              Yes         Jr          MS      
Baylor�College�of�Medicine    19  Yes Yes                                     Recent
CGG 17  Yes Yes                             MS  PhD Recent
Citi    27/28   Yes         Yes         Jr  Sr              
ExxonMobil  11  Yes         Yes Fr  Soph    Jr  Sr  PB          
    ...                                             
Flow-Cal�Inc. 16  Yes         Yes         Jr  Sr              All
Global�Shop�Solutions   18  Yes         Yes             Sr  PB          All
Harris�County�CTS   22  Yes         Yes         Jr  Sr  PB  MS  PhD All
HCSS    29  Yes         Yes Fr  Soph    Jr  Sr  PB  MS      Recent
Hitachi�Consulting    13  Yes                         Sr      MS      
HP�Inc.   1   Yes         Yes         Jr          MS      Recent
INT�Inc.  20  Yes Yes     Yes         Jr  Sr      MS  PhD 
JPMorgan�Chase�&�Co   3   Yes         Yes         Jr  Sr              
Leidos  390 Yes         Yes Fr  Soph    Jr  Sr  PB  MS      
McKesson    26  Yes                         Sr              

MRE�Consulting�Ltd. 2   Yes                         Sr  PB  MS      All
NetIQ   7               Yes     Soph    Jr  Sr  PB          
PROS    21  Yes                         Sr      MS  PhD All
San�Jacinto�College��   14              Yes     Soph    Jr  Sr  PB  MS      
SAS 4   Yes         Yes Fr  Soph    Jr  Sr  PB  MS      Recent
Smartbridge 8   Yes                         Sr  PB  MS      
Sogeti�USA    15  Yes                         Sr  PB  MS      
Southwest�Research�Institute    12  Yes         Yes         Jr  Sr  PB  MS  PhD All
The�Reynolds�and�Reynolds�Company   23  Yes Yes     Yes Fr  Soph    Jr  Sr  PB          All
UH�Enterprise�Systems   9   Yes Yes Yes Yes Fr  Soph    Jr  Sr  PB  MS  PhD All
U.S.�Marine�Corps   25  Yes         Yes Fr  Soph    Jr  Sr  PB  MS      All
ValuD�Consuting�LLC 5   Yes                         Sr  PB          All
Wipro   24  Yes                         Sr  PB          
BOOTH ORDER                                                 
    Booth   Positions               Classifications                         
Company #   Full-Time   "Full-Time
Visa Sponsor"   Part-Time   Internship  Freshman    Sophomore   Junior  Senior  Post-Bacs   MS  PhD Alumni
HP�Inc.   1   Yes         Yes         Jr          MS      Recent
MRE�Consulting,�Ltd.    2   Yes                         Sr  PB  MS      All
JPMorgan�Chase�&�Co   3   Yes         Yes         Jr  Sr              
SAS 4   Yes         Yes Fr  Soph    Jr  Sr  PB  MS      Recent
ValuD�Consuting�LLC 5   Yes                         Sr  PB          All
NetIQ   7               Yes     Soph    Jr  Sr  PB          
Smartbridge 8   Yes                         Sr  PB  MS      
UH�Enterprise�Systems   9   Yes Yes Yes Yes Fr  Soph    Jr  Sr  PB  MS  PhD All
AIG 10              Yes         Jr          MS      
ExxonMobil  11  Yes         Yes Fr  Soph    Jr  Sr  PB          
Southwest�Research�Institute    12  Yes         Yes         Jr  Sr  PB  MS  PhD All
Hitachi�Consulting    13  Yes                         Sr      MS      
San�Jacinto�College��   14              Yes     Soph    Jr  Sr  PB  MS      
Sogeti�USA    15  Yes                         Sr  PB  MS      
Flow-Cal,�Inc.    16  Yes         Yes         Jr  Sr              All
CGG 17  Yes Yes                             MS  PhD Recent
Global�Shop�Solutions   18  Yes         Yes             Sr  PB          All
Baylor�College�of�Medicine    19  Yes Yes                                     Recent
INT,�Inc. 20  Yes Yes     Yes         Jr  Sr      MS  PhD 
PROS    21  Yes                         Sr      MS  PhD All
Harris�County�CTS   22  Yes         Yes         Jr  Sr  PB  MS  PhD All
The�Reynolds�and�Reynolds�Company   23  Yes Yes     Yes Fr  Soph    Jr  Sr  PB          All
Wipro   24  Yes                         Sr  PB          
U.S.�Marine�Corps   25  Yes         Yes Fr  Soph    Jr  Sr  PB  MS      All
McKesson    26  Yes                         Sr              
Citi    27/28   Yes         Yes         Jr  Sr              
HCSS    29  Yes         Yes Fr  Soph    Jr  Sr  PB  MS      Recent
Leidos  30  Yes         Yes Fr  Soph    Jr  Sr  PB  MS      

Any input or advice? I CAN'T use pandas as much that would be lovely :)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.31472 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO