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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:02:49+00:00 2026-06-15T06:02:49+00:00

I’m relatively new to Python and wondering how best to import data from multiple

  • 0

I’m relatively new to Python and wondering how best to import data from multiple files into a single array. I have quite a few text files containing 50 rows of two columns of data (column delimited) such as:

Length=10.txt:     
1, 10    
2, 30    
3, 50   
#etc
END OF FILE

–

Length=20.txt
1, 50.7
2, 90.9
3, 10.3
#etc
END OF FILE

Let’s say I have 10 text files to import and import into a variable called data.

I’d like to create a single 3D array containing all data. That way, I can easily plot and manipulate the data by referring to the data by data[:,:,n] where n refers to the index of the text file.

I think the way I’d do this is to have an array of shape (50, 2, 10), but don’t know how best to use python to create it. I’ve thought about using a loop to import each text file as a 2D array, and then stack them to create a 2D array, although couldn’t find the appropriate commands to do this (I looked at vstack and column_stack in numpy but these don’t seem to add an extra dimension).

So far, I’ve written the import code:

    file_list = glob.glob(source_dir + '/*.TXT') #Get folder path containing text files

    for file_path in file_list:
      data = np.genfromtxt(file_path, delimiter=',', skip_header=3, skip_footer=18)

But the problem with this code, is that I can only process data when it’s in the for loop.

What I really want is an array of all data imported from the text files.

Any help would be greatly appreciated thanks!

  • 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-15T06:02:51+00:00Added an answer on June 15, 2026 at 6:02 am

    “But the problem with this code, is that I can only process data when it’s in the for loop. “

    Assuming your code works:

    # Get folder path containing text files
    file_list = glob.glob(source_dir + '/*.TXT')
    data = []
    for file_path in file_list:
        data.append(
            np.genfromtxt(file_path, delimiter=',', skip_header=3, skip_footer=18))
    # now you can access it outside the "for loop..."
    for d in data:
        print d
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article

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.