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 8019153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:18:05+00:00 2026-06-04T21:18:05+00:00

I have a file with data like: Entry Freq. 2 4.5 3 3.4 5

  • 0

I have a file with data like:

  Entry   Freq.
    2     4.5
    3     3.4
    5     4.9
    8     9.1
    12    11.1
    16    13.1
    18    12.2
    22    11.2

now the problem I am trying to solve is: I want to make it a grouped data (with range 10) based on the Entry and want to add up the frequencies falling within the range.
e.g. for above table if I group it then it should be like:

    Range   SumFreq.
     0-10    21.9(i.e. 4.5 + 3.4 + 4.9 + 9.1)
     11-20   36.4

I reached upto column separation with following code but can’t be able to perform range separation thing:
my code is:

inp = ("c:/usr/ovisek/desktop/file.txt",'r').read().strip().split('\n')
for line in map(str.split,inp):
    k = int(line[0])
    l = float(line[-1])

so far is fine but how could I be able to group the data in 10 range.

  • 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-04T21:18:07+00:00Added an answer on June 4, 2026 at 9:18 pm

    you can do something like this:

    fr = {}
    inp = open("file.txt",'r').read().strip().split('\n')
    for line in map(str.split,inp):
        k = int(line[0])
        l = float(line[-1])
        key = abs(k-1) / 10 * 10
    
        if fr.has_key(key):
            fr[key] += l
        else:
            fr[key] = l
    
    for k in sorted(fr.keys()):
        sum = fr[k]
        print '%d-%d\t%f' % (k+1 if k else 0, k+10, sum) 
    

    output:

    0-10    21.900000
    11-20   36.400000
    21-30   11.200000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have file containing data like: 12, 9 13, 9 45, 23 1, 4
I have a file data.base which looks like: 1234 XXXX 4321 XXXX 9884 ZZZZ
I have a file url that outputs like: // data = { 'ip': '',
I have a data file that looks like the following example. I've added '%'
Hi i have a yaml file like so --- data: - date: 2004-06-11 description:
I have a file whose contents are like this : control_data { some data
I have a very large XML file which has like 40000 data, and when
I have a large file which contains lots of data, and I'd like to
I have a bunch of data in a text file like this: 99150, 2012-05-18
I have an XML file containing seed data that I'm trying to load into

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.