Question: Python question about converting values from string to float. I have to write a function named convert() that takes string, file to integer column. Column

Python question about converting values from string to float.

I have to write a function named convert() that takes string, file to integer column. Column is a number that contains the values that need conversion from string to float. I have to strip newline character at the end of the line and need to slice to skip the header.

def convert(file, column): ''' try converting a column in a file with floating values from string to a list of float values. ''' col_values = [] with open(test,'r') as file: read_lns = file.readlines() for line in read_lns[1:]: next(read_lns, None) col = line.strip(' ').split() columns = col_values.append(int(col[1])) column_values = float(cols)

return column_values return col_values

It should return:

>>> type(convert(file, -2))

>>> float

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!