| | |
reading column data
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Solved Threads: 0
Hi, everyone
I have a question about reading column data from file.
helium.dat
He 1.31
He 1.32
He 1.39
He 1.41
He 1.38
He 1.39
He 1.21
He 1.45
He 2.31
I want to print just the 2nd column data(number) from helium.dat like below
1.31
1.32
1.39
1.41
1.38
1.39
1.21
1.45
2.31
I used this code, but that's wrong because loadtxt supports only numbers.
Please help me
I have a question about reading column data from file.
helium.dat
He 1.31
He 1.32
He 1.39
He 1.41
He 1.38
He 1.39
He 1.21
He 1.45
He 2.31
I want to print just the 2nd column data(number) from helium.dat like below
1.31
1.32
1.39
1.41
1.38
1.39
1.21
1.45
2.31
Python Syntax (Toggle Plain Text)
from numpy import* f = loadtxt("helium.dat") data = f[:, 1] for i in range(8): print data[i]
I used this code, but that's wrong because loadtxt supports only numbers.
Please help me
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Solved Threads: 0
First time, I think that i can't do it by myself.
But luckly, I got it.
result:
1.31
1.32
1.39
1.41
1.38
1.39
1.21
1.45
2.31
But luckly, I got it.
Python Syntax (Toggle Plain Text)
from numpy import* x0 = [] for line in file('helium.dat'): line = line.lstrip('He') line_list = [float(x) for x in line.split()] x0.append(line_list) for i in range(len(x0)): print array(x0[i]).item()
result:
1.31
1.32
1.39
1.41
1.38
1.39
1.21
1.45
2.31
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Solved Threads: 0
I got more simple code, which gives same result.
Python Syntax (Toggle Plain Text)
from numpy import* x0 = [] for line in file('helium.dat'): line = line.split() x = line[1] x0.append(x) for i in range(len(x0)): print x0[i]
![]() |
Similar Threads
- Add as reading a file (C)
- Read multiple column data from SQL query ( 1 row ) (ASP.NET)
- Reading from file, passing into function. (C)
- DBDesign - Private/Public data (Database Design)
- Datagrid to draw a table (C#)
- Reading CSV file into a ADO recordset (ASP.NET)
- Data Grid: How to include Hyperlinks (ASP.NET)
- array / data comparision help (C)
Other Threads in the Python Forum
- Previous Thread: command line arguments
- Next Thread: Problem with name not defined
Views: 2843 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied address ansi backend beginner changecolor class code conversion coordinates copy curves customdialog dan08 dictionary directory dynamic edit examples excel feet file float font format ftp function generator getvalue gui halp homework i/o images import info input ip java line linux list lists loop mouse mysql newb number numbers output panel parsing path port prime print program programming projects py2exe pygame pyqt python queue random rational recursion recursive schedule screensaverloopinactive scrolledtext searchingfile server ssh stamp statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable whileloop windows write wxpython





