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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:19:18+00:00 2026-05-20T08:19:18+00:00

The Background: I have been creating a script that based on input csv’s that

  • 0

The Background:

I have been creating a script that based on input csv’s that exist within an input directory, creates a 3 dimensional array to store the aggregated information. Each table within the array represents one of the pollution sources (eg one of the input csvs was Incinerators.csv, the created table will be the aggregated information about various pollutants released by Incinerators on a watershed scale), each row represents the aggregated information by watershed – row 0 = headers, and each column is the amount of and toxic equivalent of each substance – col 0 = watershed ID.

For each substance in each watershed, the total released by all sources is calculated and stored in another array with the exact same layout addressable using totals[wsid][substance] by index or name based dictionary lookups.

The Question:

With this table of totals, I need to calculate each watershed’s relative rank for the amount of each substance released compared to what is released in other watersheds.

I could use a couple of nested loops to go through each substance column and convert this into a list, sort the list, and then relate this back to the watershed ID… but this would not be a very clean solution. Zero values also need to be omitted from ranking and duplicate values should be given the same rank while decreasing total number being ranked.

Is there a smarter way to do this? Or a module where this is already implemented? (didn’t see anything evident in pyTables)

One of the requirements is that the solution also remain simple enough so that those with even less python experience than I will at least be able to understand the process. I can use up to 2.7.1

The End Goal:

Generate HTML pages to be iframed from a Google Earth description bubble with the results. I have put a couple entirely unfinished sample outputs here.

  • 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-20T08:19:18+00:00Added an answer on May 20, 2026 at 8:19 am

    For this I have created 2 functions

    def sortTable(table, col):
        return sorted(table, key=itemgetter(col))
    

    And

    def buildRankTable(totalTable, fieldList, wsidList, subList, subDict, wsidDict):
        ## build rankTable to mimic other templates
        rankTable = newTemplateTable(wsidList, fieldList)
    
        ## add another row to track total number ranked for each substance
        numRanked = [0 for i in range(len(fieldList))]
        numRanked[0] = "TotalNoRanked"
        rankTable.append(numRanked)
    
        for substance in subList:
            tempTable = sortTable(totalTable, subDict[substance])
            exportCsv(tempTable, outdir + os.sep + "rankT_" + substance + ".csv")
            rankList = []
            ## extract a the low to high list of wsid's, skipping non-floats (no measurement)
            for row in tempTable:
                if type(row[subDict[substance]]) == float:
                    rankList.append(row[0]) ## build wsid list in ranked order
            numRanked[subDict[substance]] = len(rankList)
    
            ## by default, this ranks low to high, we want to rank high to low starting at 1
            rankList.reverse()
    
            ## with the list of ranked wsids, get the rank and save to rankTable
            for rank, wsid in enumerate(rankList): 
                rankTable[wsidDict[wsid]][subDict[substance]] = rank + 1
    
        ## any 0 (default) values become 'NR' - No Rank
        for rowI in range(len(rankTable)):
            for colI in range(len(rankTable[rowI])):
                if rankTable[rowI][colI] == 0:
                    rankTable[rowI][colI] = "NR"
        return rankTable'
    
    • fieldList = list of fields in first row
    • wsidList = list of wsid’s (remaining 595 rows)
    • subList = list of substances to be ranked
    • subDict = dictionary to map each substance to it’s col index in totalTable
    • wsidDict = dictionary to map each wsid it it’s row index in totalTable
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: We have an application that has been in the works for over a
I have been creating an async server socket that sends and recives xml using
Background I have been asked by a client to create a picture of the
I have been asked to standardize the screen saver and desktop background used by
First a bit of background. I have been working on the MS platform for
My background is primarily as a Java Developer, but lately I have been doing
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.
Background: we have an application that generates reports from HTML (that may or may
Background I have a Windows service that uses various third-party DLLs to perform work
I have been able to set the color of the background of my UIWebView,

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.