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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:13:20+00:00 2026-05-26T21:13:20+00:00

I am having issues figuring out how to sort a large data set into

  • 0

I am having issues figuring out how to sort a large data set into more useful data.

The original file in CSV format is shown below- the data indicates x,y,z positions and finally energy. The x,y,z coordinates spread for quite a ways this is a small snippet below- basically it was an energy search over a volume.

-2.800000,-1.000000,5.470000,-0.26488315
-3.000000,1.000000,4.070000,-0.81185718
-2.800000,-1.000000,3.270000,1.29303723
-2.800000,-0.400000,4.870000,-0.51165026

Unfortunately its very difficult to plot in the requisite four dimensions so I need to trim this data. I would like to do this in such a way that I will turn the volume into a surface on the lowest energy z axis. On smaller data sets this was simple, in excel sort by X then Y and then energy, then delete all energies above the lowest. This was easy enough for small sets of data but has quickly become problematic.

I have tried various ways of doing this such as splitting the csv and using the sort command, but I am having little luck. Any advice on how to approach this would be much appreciated.

  • 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-26T21:13:20+00:00Added an answer on May 26, 2026 at 9:13 pm

    This does what you ask in your comment to Raymond’s answer — returns just the row with the lowest z for each x, y pair:

    from operator import itemgetter
    from itertools import groupby
    from csv import reader
    
    
    def min_z(iterable):
        # the data converted from strings to numbers
        floats = [[float(n) for n in row] for row in iterable]
        # the data sorted by x, y, z
        floats.sort(key=lambda (x, y, z, e): (x, y, z))
        # group the data by x, y
        grouped_floats = groupby(floats, key=itemgetter(slice(0, 2)))
        # return the first item from each group
        # because the data is sorted
        # the first item is the smallest z for the x, y group
        return [next(rowgroup) for xy, rowgroup in grouped_floats]
    
    
    data = """-2.800000,-1.000000,5.470000,-0.26488315
    -3.000000,1.000000,4.070000,-0.81185718
    -2.800000,-1.000000,3.270000,1.29303723
    -2.800000,-0.400000,4.870000,-0.51165026""".splitlines()
    
    
    print min_z(reader(data))
    

    Prints:

    [[-3.0, 1.0, 4.07, -0.81185718], 
     [-2.8, -1.0, 3.27, 1.29303723], 
     [-2.8, -0.4, 4.87, -0.51165026]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to Tomcat and I'm having some issues figuring out how to
I'm having issues figuring out where it's grabbing the default value. I tried changing
I'm very new to jQuery and having some issues figuring out stuff here :)
I've been assigned the following problem, but am having issues figuring it out. I
I'm having some trouble figuring this out. I have the following CSV string hello
I am having issues figuring out how to split on multiple delimiters using regular
I am having an issue figuring out what I thought would be a simple
I am having difficulty figuring out my unresolved external errors. I have 2 different
I'm developing an event booking application and am having difficulty figuring out how to
My company is having trouble figuring out the best way to manage our builds,

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.