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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:49:57+00:00 2026-06-18T00:49:57+00:00

I have a numpy array of dtype = object (which are actually lists of

  • 0

I have a numpy array of dtype = object (which are actually lists of various data types). So it makes a 2D array because I have an array of lists (?). I want to copy every row & only certain columns of this array to another array. I stored data in this array from a csv file. This csv file contains several fields(columns) and large amount of rows. Here’s the code chunk I used to store data into the array.

data = np.zeros((401125,), dtype = object)
for i, row in enumerate(csv_file_object):
    data[i] = row

data can be basically depicted as follows

column1  column2  column3  column4  column5 ....
1         none     2       'gona'    5.3
2         34       2       'gina'    5.5
3         none     2       'gana'    5.1
4         43       2       'gena'    5.0
5         none     2       'guna'    5.7
.....     ....   .....      .....    ....
.....     ....   .....      .....    ....
.....     ....   .....      .....    ....

There’re unwanted fields in the middle that I want to remove. Suppose I don’t want column3.
How do I remove only that column from my array? Or copy only relevant columns to another array?

  • 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-18T00:49:58+00:00Added an answer on June 18, 2026 at 12:49 am

    Use pandas. Also it seems to me, that for various type of data as yours, the pandas.DataFrame may be better fit.

    from StringIO import StringIO
    from pandas import *
    import numpy as np
    
    data = """column1  column2  column3  column4  column5
    1         none     2       'gona'    5.3
    2         34       2       'gina'    5.5
    3         none     2       'gana'    5.1
    4         43       2       'gena'    5.0
    5         none     2       'guna'    5.7"""
    
    data = StringIO(data)
    print read_csv(data, delim_whitespace=True).drop('column3',axis =1)
    

    out:

       column1 column2 column4  column5
    0        1    none  'gona'      5.3
    1        2      34  'gina'      5.5
    2        3    none  'gana'      5.1
    3        4      43  'gena'      5.0
    4        5    none  'guna'      5.7
    

    If you need an array instead of DataFrame, use the to_records() method:

    df.to_records(index = False)
    #output:
    rec.array([(1L, 'none', "'gona'", 5.3),
               (2L, '34', "'gina'", 5.5),
               (3L, 'none', "'gana'", 5.1),
               (4L, '43', "'gena'", 5.0),
               (5L, 'none', "'guna'", 5.7)], 
                dtype=[('column1', '<i8'), ('column2', '|O4'),
                       ('column4', '|O4'), ('column5', '<f8')])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have numpy array: >>> data dtype([('date', '|O4'), ('value', '<f8')] where date object is
I have an NxMx3 numpy array with dtype=object . I also have a function
I have a numpy object array containing several lists of index numbers: >>> idxLsts
I have a numpy array which came from a cv2.imread and so has dtype
I have a numpy array which contains no data values. I mask those no
I have numpy array of 1,000 elements which I want to convert to strings.
I have a numpy array of pixel data that I want to draw at
I have an numpy array which I save to a image using savefig(). Then
I have a NumPy array [1,2,3,4,5,6,7,8,9,10,11,12,13,14] and want to have an array structured like
I have a numpy array like this a = np.array(1) Now if I want

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.