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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:08:07+00:00 2026-06-10T23:08:07+00:00

Hi suppose if i have a tab seperated file like this (each field separated

  • 0

Hi suppose if i have a tab seperated file like this (each field separated by tab spaces):

Name    ID    Country    GPA
Tom    id1    USA        3.4
Jon    id2    Canada    
Amy           UK         3.0
Kevin  id4    Scotland    
Kris                     3.1

Here the density of name = 1.0 that is 100%
density of ID is 0.6 that is 60% (2 fields missing)
density of Country is 0.8
density of GPA is also 0.6

How to find this out for for a file using python? Also I need an algo that’s efficient and fast since I need to do this for thousands of files worth more than 40 GB. Map reduce code also works.
Thanks in advance 🙂

  • 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-10T23:08:09+00:00Added an answer on June 10, 2026 at 11:08 pm
    from collections import Counter
    from itertools import izip
    import csv
    
    with open(filename, 'rb') as f:
        reader = csv.reader(f, delimiter='\t')
        keys = next(reader)
        counts = Counter()
        for i, row in enumerate(reader):
            counts.update(k for k, v in izip(keys, row) if v)
        line_count = i + 1
        for k in keys:
            print k, 'density:', 1.0 * counts[k] / line_count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a tab delimited file containing user activity data formatted like this:
Suppose I have a table with data like: Tab(id, name) 1, 'Name 1' 2,
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose I have a table like: Tab(MyDate datetime null, MyIs bit null, ...) Then
Suppose I have a table with a column name varchar(20) , and I store
I have a WPF Menu and a Tab control. I would like the list
I have idea to implement my wpf windows like TabPages in tab control. It
I've got a bad tab separated file that I need to clean up. The
Suppose , i have a tab activity consist of a TabHost. The TabHost contains
Suppose I have a simple makefile like: hello: echo hello world bye: echo bye

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.