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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:46:17+00:00 2026-05-27T11:46:17+00:00

I want to know how I should index / access some data programmatically in

  • 0

I want to know how I should index / access some data programmatically in python.
I have columnar data: depth, temperature, gradient, gamma, for a set of boreholes. There are n boreholes. I have a header, which lists the borehole name and numeric ID. Example:

Bore_name,Bore_ID,,,Bore_name,Bore_ID,,,, ... 
<a row of headers>
depth,temp,gradient,gamma,depth,temp,gradient,gamma ...

I don’t know how to index the data, apart from rude iteration:

with open(filename,'rU') as f:
    bores = f.readline().rstrip().split(',')   
    headers = f.readline().rstrip().split(',')


# load from CSV file, missing values are empty 'cells'
tdata = numpy.genfromtxt(filename, skip_header=2, delimiter=',', missing_values='', filling_values=numpy.nan)

for column in range(0,numpy.shape(tdata)[1],4):  
    # plots temperature on x, depth on y
    pl.plot(tdata[:,column+1],tdata[:,column], label=bores[column])
    # get index at max depth
    depth = numpy.nanargmin(tdata[:,column])
    # plot text label at max depth (y) and temp at that depth (x)
    pl.text(tdata[depth,column+1],tdata[depth,column],bores[column])

It seems easy enough this way, but I’ve been using R recently and have got a bit used to their way of referencing data objects via classes and subclasses interpreted from headers.

  • 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-27T11:46:18+00:00Added an answer on May 27, 2026 at 11:46 am

    Well if you like R’s data.table, there have been a few (at least) attempts to re-create that functionality in NumPy–through additional classes in NumPy Core and through external Python libraries. The effort i find most promising is the datarray library by Fernando Perez. Here’s how it works.

    >>> # create a NumPy array for use as our data set
    >>> import numpy as NP
    >>> D = NP.random.randint(0, 10, 40).reshape(8, 5)
    
    >>> # create some generic row and column names to pass to the constructor
    >>> row_ids = [ "row{0}".format(c) for c in range(D1.shape[0]) ]
    >>> rows = 'rows_id', row_ids
    
    >>> variables = [ "col{0}".format(c) for c in range(D1.shape[1]) ]
    >>> cols = 'variable', variables
    

    Instantiate the DataArray instance, by calling the constructor and passing in an ordinary NumPy array and a list of tuples–one tuple for each axis, and since ndim = 2 here, there are two tuples in the list each tuple is comprised of axis label (str) and a sequence of labels for that axes (list).

    >>> from datarray.datarray import DataArray as DA
    >>> D1 = DA(D, [rows, cols])
    
    >>> D1.axes
          (Axis(name='rows', index=0, labels=['row0', 'row1', 'row2', 'row3', 
               'row4', 'row5', 'row6', 'row7']), Axis(name='cols', index=1, 
               labels=['col0', 'col1', 'col2', 'col3', 'col4']))
    
    >>> # now you can use R-like syntax to reference a NumPy data array by column:
    >>> D1[:,'col1']
          DataArray([8, 5, 0, 7, 8, 9, 9, 4])
          ('rows',)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

He want's to know our opinions on whether we should have flexitime, allow non-work
I have a data structure that I want to access / modify in different
I want to know if the system has a attached webcam. How should i
I want to know the version of a mp3 file format. What should I
I want to know what are the options to do some scripting jobs in
I want to know if it is possible to use the same index file
I have a variable I want to access in my application.html.erb so it is
I want to know the effective algorithms/data structures to identify the below information in
I want to know who refers my webpage, so in my models I have:
Want to know what the stackoverflow community feels about the various free and non-free

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.