Python Forum

Full Version: Convert .csv string into float
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys!

The file that results of a test I did is a .csv file, containing results only in str type.
How can I convert only a specific entire column of the .csv file into float?

Example that sums up my case:
ResultFile.csv (2 lines, 6 columns):
Output:
Hello,how,are,you,1,2 I,hope,you're,good,3,4
If I'd type the following command:
sample = open('path','r')
for line in sample:
   info = line.split(',')
   print (type(info[4]))
I'd like the result to be:
Output:
<type 'float'> <type 'float'>
How do I need to treat the .csv file to obtain that, while the type for all other columns remains str??????