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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:46:24+00:00 2026-06-15T11:46:24+00:00

I founds this error in multiple question but it is not fixed or explained

  • 0

I founds this error in multiple question but it is not fixed or explained
Ex. Reading in single str column with loadtxt

I have a problem with the following line (import numpy as np)

    symbols = np.loadtxt('filename.csv',
               dtype={'names': ('ticker', 'year', 'month','day'),
                      'formats': ('S10','i4','i2','i2')},
                delimiter=',',skiprows=1, usecols=(0,))

with following data

ticker  year    month   day
GPD.TO  2010    8   16
HAO.V   2010    8   16
RDS.V   2010    8   16
MD.V    2010    8   16

It gives me a

IndexError: list index out of range

When I run that line without usecols it works fine and returns all 4 columns fine.

I looked at many other questions on google and Stackoverflow but this isnt answered

  • 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-15T11:46:25+00:00Added an answer on June 15, 2026 at 11:46 am

    If you want to use usecols = (0,) with np.loadtxt then you must change the dtype to match:

    import numpy as np
    symbols = np.loadtxt('filename.csv',
                         dtype={'names': ('ticker', ),
                                'formats': ('S10',)},
                         delimiter=',',
                         skiprows=1,
                         usecols=(0,)
                         )
    print(symbols)
    

    with filename.csv:

    ticker,year,month,day
    GPD.TO,2010,8,16
    HAO.V,2010,8,16
    RDS.V,2010,8,16
    MD.V,2010,8,16
    

    yields

    [('GPD.TO',) ('HAO.V',) ('RDS.V',) ('MD.V',)]
    

    Alternatively, with np.genfromtxt you do not need to change dtype:

    symbols = np.genfromtxt('filename.csv',
                            dtype={'names': ('ticker', 'year', 'month','day'),
                                   'formats': ('S10','i4','i2','i2')},                        
                            delimiter=',',
                            skiprows=1,
                            usecols=(0,)
                            )
    

    works as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found plenty of information out there about this error: 'ERROR: Could not
I have very simple question. I am not using it but I have curiosity
I found a workaround for this error, but am now really curious as to
I encountered this error: The type or namespace name 'WebControls' could not be found
I am receiving this error A route named 'MemberRoute' could not be found in
Why I get this error? Page not found (404) Using the URLconf defined in
Getting Expected ',' or '{' but found '#44559' error. My code looks like this:
Here is a related question I found, but it does not answer my question
I am not entirely sure how to better word this question, as I am
Anyone know what this error means? after googling I found a bunch of sites

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.