As a new student please forgive my ignorance, I have searched a lot and have not solved my problem is. I need to import a CSV file with mixed data type [int, float and string], set the data type, then math on the inters and floats.
The problem is that the CSV reader changes everything to wire (or are they already wired?). I am trying and I can make the float secret and if it gives an error message then I know that it is a string, but how will I tell that it is a float because my program needs to be set between two is?
I am only allowed to import CSV, and no other. This is my second year of Python theme, and in fact it is not sure how to do it.
Edit, got an answer that looks like my problem, but it still returns the wrong answer, usually ints, but not always as usual, still returned as string type Goes to:
import csv tests = [# (type, test) (int, int), (float, float),] def getType (value): for typ, test test : Try: Value except error (value) Return Printer: Print 'Value Error' Release # Returns a Match Return L = open ( "Adultkcsv") reader = CSV reader (file) File Name = "Autput.aksmel 'text = open (filename," w ") text. Written ('& lt;? Xml version = "1.0"? & Gt;'); Header = Reader.ext () for header in text.write ('& lt;! DOCTYPE summary' [']': Print '& lt; name & gt; Print' & lt; / name & gt; Print In [1]: print getType [a] # in the field for the row: # text = row [2] # print type (text) print '& lt; / dataType & gt; ; '# Print Type (Value) Print' & lt ;! ELEMENT Summary \ n \ n & gt; # Text.write ('& lt; Element & gt;')
/ P>
Hard work should be done, however trustworthy right type
No comments:
Post a Comment