Click here to Skip to main content
15,064,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a file with many lines and 13 columns, I want to only use 8 lines of it. How do I read in the file and only use 8 lines of it. I have it that I can read in the file but its just taking in and print the whole thing which I dont need, is there a way to only read in whats needed or to assign certain lines to a variable?
I also want to create a histogram of the data in thos 8 lines but not including the first column, so I also need a way to exclude that?

What I have tried:

filename = "labdata.txt"


in_file = open(filename, 'r') 

data = in_file.readlines() 

for line in data:
	sdata = line.split(' ')  
	print(sdata) 

infile.close()  



Also tried this format
file_name = 'labdata.txt'

in_file = open(file_name, 'r')

header = in_file.readline()
print(header)

data = in_file.read()


print(data)
Posted
Updated 9-May-20 22:00pm
v2

1 solution

Use the readline function in a loop and save only the lines that you want.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900