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

  • SEARCH
  • Home
  • 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 8621301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:47:23+00:00 2026-06-12T06:47:23+00:00

I am trying to learn some python coding on my own and I came

  • 0

I am trying to learn some python coding on my own and I came through this problem::

Input Text File Contents::

10280341|2012-10-03 19:11:06.390|Sami|abc|Crossword|70
10280343|2012-10-03 19:15:32.173|Sami|aaa|Sudoku|30
10280355|2012-10-04 19:18:32.173|miami|bbb|Chaircar|15
10280366|2012-10-04 19:19:32.173|miami|bob|Avista|35

Output Expected::

2012-10-03 Sami|2|100
2012-10-04 miami|2|50

I know this can be done through String Parsing & Matching but I do not have any idea, where to start. Any links or pointers would be highly helpful to any similar problem.
TIA

  • 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-06-12T06:47:25+00:00Added an answer on June 12, 2026 at 6:47 am

    You could use itertools.groupby as has already been suggested, or make use of the csv.reader object which is already a generator and a collections.defaultdict to aggregate the value column…

    import csv
    from collections import defaultdict
    
    summary = defaultdict(list)
    csvin = csv.reader(open('testdata.txt'), delimiter='|')
    for row in csvin:
        summary[(row[1].split(' ')[0], row[2])].append(int(row[5]))
    
    csvout = csv.writer(open('testdata.out','wb'), delimiter='|')
    for who, what in summary.iteritems():
        csvout.writerow( [' '.join(who), len(what), sum(what)] )
    

    If you’re looking at more complicated cross tabulation/pivoting etc…, then it may well be worth having a look at pandas which is a very useful library based on numpy

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn the python scripting . Being some body who started coding
I'm trying to learn python but have some problem running source files from power
I'm trying to learn python and have encountered some strange behaviour. I am experimenting
I am trying to learn doxygen by running following Python file. A similar attempt
first question here. I am trying to learn python by stepping through project euler,
So I'm trying to learn Python using some tutorials, and I decided to create
I'm trying to learn Python through Learn Python the Hard Way. I'm now on
Trying to learn some geospatial python. More or less following the class notes here
I am just trying to learn some Lisp, so I am going through project
I'm trying to learn some Rails but I seem to get stuck on this

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.