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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:09:35+00:00 2026-06-14T19:09:35+00:00

I am having the x-value and corresponding counts in a file. I read that

  • 0

I am having the x-value and corresponding counts in a file. I read that as list of tuples in the following form

dat = [(0.02, 1), 
(0.0211, 1), 
(0.021, 1), 
(0.023, 1), 
(0.0251, 1), 
(0.12, 2), 
(0.141, 1), 
(0.14, 3), 
(0.171, 1), 
(0.462, 9),
(0.467, 10),
(0.478, 15), 
(0.804, 20), 
(0.815, 31), 
(0.815, 24),
(2.72, 164), 
(2.78, 147), 
(2.8, 128),
(5.78, 6), 
(5.83, 1), 
(5.8603, 1),
(5.94, 17), 
(8.63, 3), 
(8.87, 5),  
(18.601, 1), 
(19.0, 7), 
(21.0, 2), 
(22.0, 4)]

How to convert these into equal interval counts. For example, an intervals with 0.2 increments.

x    count
0    0
0.5  12
1.0  75
1.5  0
2.0  0
2.5  0
3.0  439
... 
  • 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-14T19:09:36+00:00Added an answer on June 14, 2026 at 7:09 pm

    An approach with pandas:

    In [74]: df = pd.DataFrame.from_records(dat).set_index(0)
    
    In [75]: counts = df.groupby(lambda x: floor(x / 0.5) * 0.5).count()
    
    In [76]: counts
    Out[76]: 
           1
    0.0   12
    0.5    3
    2.5    3
    5.5    4
    8.5    2
    18.5   1
    19.0   1
    21.0   1
    22.0   1
    

    You can fill the intervals with zero counts:

    In [77]: counts.reindex(np.arange(0, 22, 0.5)).fillna(0)
    Out[73]: 
           1
    0.0   12
    0.5    3
    1.0    0
    1.5    0
    2.0    0
    2.5    3
    3.0    0
    3.5    0
    4.0    0
    
    etc ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem assigning a default value to my Spring Form input
i am getting unpredictable error when two of NSMutableArray having same value at index
I have 3 select boxes and all are having same value (clones) & created
Is it possible in MSBuild to batch tasks without having the metadata value you
I have ImageButton with CommandArgument attribute which is having multiple Eval value. When I
Im having an issue where Im getting an empty value for the value of
I am having problem to get a numerical value for this expression where I
I am having trouble passing the return value from TheMethod() to Main and displaying
I am having trouble converting a value in a string array to int since
I am having difficulty understanding the part value : value == 0 ? How

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.