خرید بک لینک

Vote count: 0

I have a file text with data in a following format:

rubbish & 3.97& 3.83& 3.95& 3.83& 3.82

rubbish & 4.92& 4.81& 4.88& 4.81& 4.81

rubbish & 5.90& 5.66& 5.88& 5.66& 5.66

rubbish &--- & 6.05& 6.14& 6.05& 6.05

rubbish & 6.42& 6.26& 6.46& 6.26& 6.26

rubbish &--- & 6.56& 6.63& 6.56& 6.56

And I want to read them into numpy.array object so that numbers are transformed into floating point number object while the --- stay as the string objects. However, the following piece of code creates an expected numpy.array object but everything in there is a string.

import numpy as np

wejscie = open('data.dat', 'r').readlines()

def fun1(x):

  print x
  if x.strip() == '---':

    retu str(x)

  else:

    retu float(x)

dane = np.array([map(fun1, linijka.split('&')[1:]) for linijka in wejscie])

So why doesn't my fun1 function work properly?

asked 37 secs ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 14 مرداد 1395 ساعت: 20:58

صفحه بندی