Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6849107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:56:58+00:00 2026-05-27T00:56:58+00:00

I would like to sum amount by a company name, but often format of

  • 0

I would like to sum amount by a company name, but often format of company name is different.. such as Apple Inc is sometimes Apple computer, Apple Inc.
Also.. I don’t know how I could handle “header”

My file format is CSV.

company amount
a   20
b   10
A'  30
bb  20

I would like to do like this:

line = readline() if line=='':
break
if 'Apple' in line:
sum(amount)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:56:59+00:00Added an answer on May 27, 2026 at 12:56 am

    You’re going to need to map the name variations somehow, either by totaling each name separately and combining afterward by hand, or by making a dictionary up front that identifies all the aliases used by each company. if 'Apple' in line: fails hard because it can undetectably mix the amounts from different companies together.

    Company = {"Apple": 1, "Apple Computer": 1, "AAPL": 1, "Apple, Inc": 1,
               "Apple Vacations": 2, "Applebee's Restaurant": 3 }
    
    sum[Company[name]] += amount
    

    Edit 2: If you don’t know all the company names beforehand, then the best you can do is keep track of the unique names contained in the input file and decide whether to merge them later:

    Company = {}
    for <name, amount> in file:  # pseudo-code for reading and parsing the input
        if name in Company:
            Company[name] += amount
        else:
            Company[name] = amount
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would like to be able to set colors of headings and such, different font
I would like to achieve SELECT @param1, @param2, @param3, t.field1, sum(t.amount) FROM table t
sum( int(i.replace(',',''))if re.search('\d',i)!=None for i in list) I would like to sum all elements
I would like do some thing like this: SELECT sum(quantity) FROM orders WHERE order_code
I would like to do the following: SELECT sum(max(field-10,000,0)) from TABLE as in, I
I would like to perform something similar to this (ie get the sum of
I have a DataView in which I would like to sum a column called
I have a TSQL Query that does something like this: SELECT SUM(s.Amount) as TotalSales,
Would like to know what a programmer should know to become a good at
Would like to make anapplication in Java that will not automatically parse parameters used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.