Text Files- Problem with columns.

This is the place for queries that don't fit in any of the other categories.

Text Files- Problem with columns.

Postby Nebula9003 » Sat Oct 19, 2013 4:52 pm

I am trying to write a code to read my txt files and plot a graph based on certain formulas applied to the values in the file.
There are 3 columns in the file.

Code: Select all
for infile in glob.glob('*.txt'):
       dataset = open(infile).readlines()[24:]
       data = np.genfromtxt(dataset, delimiter=' ', usecols = (1, 2, 3))
       lta= data


This gives me the following error:

ValueError: Some errors were detected !
Line #1 (got 1 columns instead of 3)
Line #2 (got 1 columns instead of 3)
Line #3 (got 1 columns instead of 3)
Line #4 (got 1 columns instead of 3)
Line #5 (got 1 columns instead of 3)
Line #6 (got 1 columns instead of 3)... uptil line#26

Example of the txt file:

1000.0000000000 -0.0044577198 24.1055448339
794.3282347243 -0.0039530944 24.1085754702
630.9573444802 -0.0035102328 24.1113209483
501.1872336273 -0.0031515122 24.1139025515
398.1071705535 -0.0028364689 24.1163238128

There are 4 files in the folder for which the data directory was was set at the beginning of the code.Each file has 51 rows (example above) and 3 columns Any help is appreciated.
I am new to python so a little confused with this. I am also sorry if the format for this question is a little off. I am new to this site as well. Thank you again.
Last edited by stranac on Sat Oct 19, 2013 8:07 pm, edited 4 times in total.
Reason: First post lock
Nebula9003
 
Posts: 1
Joined: Sat Oct 19, 2013 4:48 pm

Re: Text Files- Problem with columns.

Postby stranac » Sat Oct 19, 2013 8:08 pm

Those are tabs, not spaces.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1115
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron