Question

In: Computer Science

#This is what you have to do: #1.Open the testFile.csv #2.Process each line so you create...

#This is what you have to do:
#1.Open the testFile.csv
#2.Process each line so you create dictionary where key is name of the company and value is a net balance
#2.a.   First column of each row is a name of the company
#2.a.a. Utes company has different types of spelling, so you need to put all of them under the same key
#2.b.   Second column is payments in
#2.c.   Third column is payments out. Note that they can be negatives as well.
#       Hint: Absolute value could be derived by using abs( number )
#2.d.   Your net balance is sum(payments in - payments out)
#3. Print resulting dictionary
#4. Upload the printed result along with this file

TEST FILE INFO

Counterparty Amount Received Amount Paid
Utes 0 1100070
Vlas Fancy LLC 0 -5699995
Thurinus Adoptations 0 3471334
Utes 0 8146767
Limited Limits LLC 4744912 0
Vlas Fancy LLC 0 2936543
LLC Utes 4170585 0
Caesarian Trust 7681654 0
Vlas Fancy LLC 0 7550468
Salv CLL 0 3625075
Utes LLC 0 -6601733

Solutions

Expert Solution

# dictionary for holding the data,Utes is initialised to 0 since
# its in multiple names and we have to add its net balance to current one
companies = {'Utes':0}

#1.Open the testFile.csv
with open('testFile.csv') as csvfile:

    # for first line/header detection
    i = 1

    # looping through each line in the csvfile
    for row in csvfile:

        # if its first line/header skip to next
        if i == 1:
            i = 2
            continue

        # removing \n character in the end
        row = row.replace('\n','')

        # first element when row splited with '\t' will be Counterparty [since \t is the delemiter]
        Counterparty = row.split('\t')[0]

        # second element when row splited with '\t' will be AmountReceived [since \t is the delemiter]
        AmountReceived = row.split('\t')[1]

        # third element when row splited with '\t' will be AmountPaid [since \t is the delemiter]
        AmountPaid = row.split('\t')[2]

        # calculating net balance as sum of amount in - amount out
        NetBalance = int(AmountReceived)-abs(int(AmountPaid))

        # checking if Utes is in Counterparty
        if 'Utes' in Counterparty:
            # if true then add NetBalance to current Utes NetBalance,Thats why Utes is initialised with 0
            companies['Utes'] += NetBalance

        # checking for existing Counterparty
        elif Counterparty in list(companies.keys()):
            companies[Counterparty] += NetBalance

        else:
            # else set Counterparty as the key and NetBalance as the value
            companies[Counterparty] = NetBalance

# printing the final dictionary
print(companies)

testFile.csv

Code Screenshot

Output-:

PS-:If you have any doubts/problems please comment below


Related Solutions

Process each line so you create dictionary where key is name of the company and value...
Process each line so you create dictionary where key is name of the company and value is a net balance #2.a. First column of each row is a name of the company #2.a.a. Utes company has different types of spelling, so you need to put all of them under the same key #2.b. Second column is payments in #2.c. Third column is payments out. Note that they can be negatives as well. # Hint: Absolute value could be derived by...
1) Where do you start translation? 2) Where do you stop translation? 3) What does Open...
1) Where do you start translation? 2) Where do you stop translation? 3) What does Open Reading Frame mean? 4) What does it mean that the genetic code is redundant?
Using what you have learned about process mapping in this week’s resources, create a process mapping...
Using what you have learned about process mapping in this week’s resources, create a process mapping flowchart to measure operational data of the activity using Microsoft PowerPoint or Microsoft Visio. Identify the important measurements within your process which provide operational data. Then, based on the process map you have created, list and describe these measurements and the critical path within your process, utilizing any additional process improvement tools necessary. Your completed Assignment should include the flowchart, a description of process...
Using what you have learned about process mapping in this week’s resources, create a process mapping...
Using what you have learned about process mapping in this week’s resources, create a process mapping flowchart to measure operational data of the activity using Microsoft PowerPoint or Microsoft Visio. Identify the important measurements within your process which provide operational data. Then, based on the process map you have created, list and describe these measurements and the critical path within your process, utilizing any additional process improvement tools necessary. Your completed Assignment should include the flowchart, a description of process...
What effects do 1. adverse selection and 2. moral hazard have on the money loaning process...
What effects do 1. adverse selection and 2. moral hazard have on the money loaning process respectively and how can their negative effects be negated? ※Many thanks in advance!
1-What ethical conflict have observed in the clinical setting? What did you do? 2-If you have...
1-What ethical conflict have observed in the clinical setting? What did you do? 2-If you have not yet observed one, is there an conflict with duties to self and duties to the client?
1. what part of the digestive process are under voluntary control? 2. How do you suppose...
1. what part of the digestive process are under voluntary control? 2. How do you suppose damage to the vagus nerve (a parasympathetic nerve) would impact digestive processes? 3. what digestive functions does the pancreas perform?
1) What is a trial balance, why do we create it? 2) What are adjustment journal...
1) What is a trial balance, why do we create it? 2) What are adjustment journal entries? Why do we record the adjustment journal entries? 3) What is the purpose of writing an adjusted Trial balance? 4) How adjustment journal entries are different from the closing journal entries?
What do you think about this so-called “Shareholder vs. Stakeholder” debate? Do you have any personal...
What do you think about this so-called “Shareholder vs. Stakeholder” debate? Do you have any personal experiences where you have observed the effects of this debate in terms of corporate actions? On which side of the argument do you come down on and why?
List and explain each of the stages in the juvenile justice process. What do you view...
List and explain each of the stages in the juvenile justice process. What do you view as the most critical stage? Why?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT