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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:24:21+00:00 2026-06-10T10:24:21+00:00

I have a data file that consists of several data points, that i would

  • 0

I have a data file that consists of several data points, that i would like to plot in a particular order. Here is the example data file:

cop   94.0528    313     441
cpr   225.172    726     747
ent   444.786    926     939
fsh   256.038    743     754
fsp   43.7764    340     356
pbp   343.708    825     834
rho   426.497    858     886
sca   342.431    427     872

I am currently plotting those just below each other in the way i set the example. How can i change the order of those data records within my python script to a specified order? I already tried to work this into an array. in this question here: How do i control the sequence of records in a bar plot with matplotlib?

So the next question i have from here on out is, can i do the exact same thing, but using a text-based sorting aaray?

So what i would put in would be something like this:

posarray = (crp, 2), (cop,1)

edit: The posarray would denote the position of the record with the text in posarray[0] in the outputarray. The crp would end up at the second position, cop at the first and so on.

and what it would give me would be

cop   94.0528    313     441
cpr   225.172    726     747

the best thing would be using some kind of insert, so that if i forget to mention an item in the sorting array it would sink to the bottom.

  • 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-10T10:24:23+00:00Added an answer on June 10, 2026 at 10:24 am

    As described in the answer to your previous question, you can achieve what you want with some indexing trick.

    Let’s assume that you have a numpy representation of your array as such:

    a = array([('cop', 94.0528, 313, 441), ('cpr', 225.172, 726, 747),
               ('ent', 444.786, 926, 939), ('fsh', 256.038, 743, 754),
               ('fsp', 43.7764, 340, 356), ('pbp', 343.708, 825, 834),
               ('rho', 426.497, 858, 886), ('sca', 342.431, 427, 872)], 
              dtype=[('f0', '|S3'), ('f1', '<f8'), ('f2', '<i8'), ('f3', '<i8')])
    

    You can easily get a list of your first column:

    >>> fields = list(a['f0'])
    

    Now, define a list of the fields ordered as you want, for example:

    >>> new_order = ['cpr', 'cop', 'ent', 'fsh', 'fsp', 'rho', 'pbp', 'sca']
    

    You can get the position of each item of new_order in your fields list by using the index method and some list comprehension:

    >>> indices = [fields.index(i) for i in new_order]
    [1, 0, 2, 3, 4, 6, 5, 7]
    

    (You can understand why we needed fields to be a list, as an array doesn’t have a index method)

    That’s it. You can now reorder your array with the indices list:

    >>> a[indices]
    array([('cpr', 225.172, 726, 747), ('cop', 94.0528, 313, 441),
           ('ent', 444.786, 926, 939), ('fsh', 256.038, 743, 754),
           ('fsp', 43.7764, 340, 356), ('rho', 426.497, 858, 886),
           ('pbp', 343.708, 825, 834), ('sca', 342.431, 427, 872)], 
          dtype=[('f0', '|S3'), ('f1', '<f8'), ('f2', '<i8'), ('f3', '<i8')])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data file that consists of several data points, that i would
I have a data file that looks like the following example. I've added '%'
I have a data file that looks like this: xyz123 2.000 -0.3974 0.0 hij123
I have a data file with the # sign as delimiter, that I would
I have some data files from a legacy system that I would like to
I have been given a file that I would like to extract the useful
I have a TSV file that consists of integers along with some false data
Say I have a data file that I want to process; I want to
I have a text data file that I likely will read with readLines .
I have an HTML (App) file that reads another HTML (data) file via jQuery.ajax()

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.