0

My goal is to be able to have any excel spreadsheet (that I will save as a .cvs), and read it in python. I know how to extract the data and so far my code is this...

    file = input("insert csv file name to upload: ")
    with open(file) as csvfile:
        readCSV = csv.reader(csvfile, delimiter = ',')
    # opens any csv file if input is correct with .csv extention    

        x = []
        y = []

        for row in readCSV:                 
            x_values = row[0]
            y_values = row[1]

            x.append(x_values)
            y.append(y_values)

    X = x[1:]                               # gets rid of first line(title)
    Y = y[1:]

    X = [float(i) for i in X]
    Y = [float(i) for i in Y]

So this is fine in excel if the data is in the nice format of first row = "title" and the rest are values. But how can I filter through the whole thing and ignore any text?

I tried .isdigit(), but I ran into problems there when floats were introduced.

Liam
  • 1
  • 3
  • found [this post](http://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-number-float-in-python) with an excellent replacement of .isdigit() – Bill Huang Jun 11 '15 at 18:52

1 Answers1

0

If the data in the spreadsheet is actually numbers (and not text), then you could use the xlrd package to work directly with the .xls file and check the data type of each cell.

Ethan Furman
  • 63,992
  • 20
  • 159
  • 237