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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:50:25+00:00 2026-06-06T07:50:25+00:00

I have a data file, which I need to read. I know to read

  • 0

I have a data file, which I need to read. I know to read files in Python you have to do something like:

file = open(fileLocaion, 'r+')

But I do not know who to do special reads. The data I have is in columns. So x values in one column and y values in another with headers at the top. The data (my text file a.txt) looks like

 Charge (1x), Ch A, Run #1
 Time ( s ) Charge (1x) ( µC )
 0.0000 0.021
 0.1000 0.021
 0.2000 0.021
 0.3000 0.021
 0.4000 0.021
 0.5000 0.021
 0.6000 0.021

So the first time value is 0.0000 and the first charge value is 0.021. I want to be able to take this into Python and use matplotlib to plot it. But I am having trouble figuring out how to read this data.

  • 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-06T07:50:27+00:00Added an answer on June 6, 2026 at 7:50 am

    If you’re going to be plotting it with matplotlib, probably the simplest thing to do is to use numpy.loadtxt [docs], because you’ll have numpy installed anyway:

    >>> import numpy
    >>> d = numpy.loadtxt("mdat.txt", skiprows=2)
    >>> d
    array([[ 0.   ,  0.021],
           [ 0.1  ,  0.021],
           [ 0.2  ,  0.021],
           [ 0.3  ,  0.021],
           [ 0.4  ,  0.021],
           [ 0.5  ,  0.021],
           [ 0.6  ,  0.021]])
    

    Note that I had to add skiprows=2 here to skip the header. Then the times are d[:,0] and the charges d[:,1], or you could get them explicitly with loadtxt:

    >>> times, charges = numpy.loadtxt("mdat.txt", skiprows=2, unpack=True)
    >>> times
    array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6])
    >>> charges
    array([ 0.021,  0.021,  0.021,  0.021,  0.021,  0.021,  0.021])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file which contains data seperated by '|'. I need to
I have few text and excel file, from which I need to import data
I have a file data.base which looks like: 1234 XXXX 4321 XXXX 9884 ZZZZ
I have a very large XML file which has like 40000 data, and when
I have text file(test.data), which include(this is just example other files have more values....)
I have a data file which is comprised of rows of data, newline separated.
I have a System.Data.DataTable which is populated by reading a CSV file which sets
I have .zip file which contain csv data. I am reading .zip file using
I have a txt file which contains data in the following format: X1 Y1
I have an excel file which is refreshing data every few seconds and running

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.