當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.recfromcsv方法代碼示例

本文整理匯總了Python中numpy.recfromcsv方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.recfromcsv方法的具體用法?Python numpy.recfromcsv怎麽用?Python numpy.recfromcsv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.recfromcsv方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_recfromcsv

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import recfromcsv [as 別名]
def test_recfromcsv(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(missing_values="N/A", names=True, case_sensitive=True)
        test = np.recfromcsv(data, dtype=None, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', np.int), ('B', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromcsv(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
        #
        data = TextIO('A,B\n0,1\n2,3')
        test = np.recfromcsv(data, missing_values='N/A',)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('a', np.int), ('b', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:27,代碼來源:test_io.py

示例2: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import recfromcsv [as 別名]
def __init__(self):
        # Load data from file using numpy magic
        data = np.recfromcsv('cmf_data/fulda_climate.csv', encoding='utf-8')

        def bstr2date(bs):
            """Helper function to convert date byte string to datetime object"""
            return datetime.datetime.strptime(bs, '%d.%m.%Y')

        # Get begin, step and end from the date column
        self.begin = bstr2date(data.date[0])
        self.step = bstr2date(data.date[1]) - self.begin
        self.end = bstr2date(data.date[-1])

        def a2ts(a):
            """Converts an array column to a timeseries"""
            return cmf.timeseries.from_array(self.begin, self.step, a)

        self.P = a2ts(data.prec)
        self.T = a2ts(data.tmean)
        self.Tmin = a2ts(data.tmin)
        self.Tmax = a2ts(data.tmax)
        self.Q = a2ts(data.q) 
開發者ID:thouska,項目名稱:spotpy,代碼行數:24,代碼來源:spot_setup_cmf_lumped.py

示例3: geticbcnames

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import recfromcsv [as 別名]
def geticbcnames(inpath):
    import io
    import re
    import numpy as np
    with open(inpath) as infile:
        intxt = infile.read()
    result = re.findall("(TYPE_\S+\s*=\s*(('[^\n]+',\s*)+))", intxt)
    names = result[0][1].strip()[1:-1].replace("'", '') + '\n'
    nflds = len(names.split(':'))
    if nflds == 16:
        fmts = 'S16 f c f c f c f S16 f c c b b b b'.split()
    else:
        fmts = 'S16 f c f c f c f S16 f c b b b b'.split()
    data = re.sub('\s+', '', result[1][1])[:-1]
    data = re.sub("'", '', data)
    data = re.sub(",", '\n', data)
    data = (names + data).encode()
    rdata = np.recfromcsv(io.BytesIO(data), delimiter=b':', dtype=fmts)
    icbc_sur = []
    for row in rdata:
        if row['icbc_sur'] != b'':
            icbc_sur.append(row['icbc_sur'].decode().strip())
    icbc_sur = set(icbc_sur)
    result = icbc_sur.union([s.decode().strip() for s in rdata['spc']])
    return list(result) 
開發者ID:barronh,項目名稱:pseudonetcdf,代碼行數:27,代碼來源:pncglobal2cmaq.py

示例4: test_dtype_with_converters_and_usecols

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import recfromcsv [as 別名]
def test_dtype_with_converters_and_usecols(self):
        dstr = "1,5,-1,1:1\n2,8,-1,1:n\n3,3,-2,m:n\n"
        dmap = {'1:1':0, '1:n':1, 'm:1':2, 'm:n':3}
        dtyp = [('e1','i4'),('e2','i4'),('e3','i2'),('n', 'i1')]
        conv = {0: int, 1: int, 2: int, 3: lambda r: dmap[r.decode()]}
        test = np.recfromcsv(TextIO(dstr,), dtype=dtyp, delimiter=',',
                             names=None, converters=conv)
        control = np.rec.array([(1,5,-1,0), (2,8,-1,1), (3,3,-2,3)], dtype=dtyp)
        assert_equal(test, control)
        dtyp = [('e1','i4'),('e2','i4'),('n', 'i1')]
        test = np.recfromcsv(TextIO(dstr,), dtype=dtyp, delimiter=',',
                             usecols=(0,1,3), names=None, converters=conv)
        control = np.rec.array([(1,5,0), (2,8,1), (3,3,3)], dtype=dtyp)
        assert_equal(test, control) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:16,代碼來源:test_io.py

示例5: test_recfromcsv

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import recfromcsv [as 別名]
def test_recfromcsv(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(missing_values="N/A", names=True, case_sensitive=True)
        test = np.recfromcsv(data, dtype=None, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', int), ('B', int)])
        assert_(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromcsv(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', int), ('B', int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
        #
        data = TextIO('A,B\n0,1\n2,3')
        test = np.recfromcsv(data, missing_values='N/A',)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('a', int), ('b', int)])
        assert_(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,3')
        dtype = [('a', int), ('b', float)]
        test = np.recfromcsv(data, missing_values='N/A', dtype=dtype)
        control = np.array([(0, 1), (2, 3)],
                           dtype=dtype)
        assert_(isinstance(test, np.recarray))
        assert_equal(test, control)

        #gh-10394
        data = TextIO('color\n"red"\n"blue"')
        test = np.recfromcsv(data, converters={0: lambda x: x.strip(b'\"')})
        control = np.array([('red',), ('blue',)], dtype=[('color', (bytes, 4))])
        assert_equal(test.dtype, control.dtype)
        assert_equal(test, control) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:42,代碼來源:test_io.py

示例6: test_dtype_with_converters_and_usecols

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import recfromcsv [as 別名]
def test_dtype_with_converters_and_usecols(self):
        dstr = "1,5,-1,1:1\n2,8,-1,1:n\n3,3,-2,m:n\n"
        dmap = {'1:1':0, '1:n':1, 'm:1':2, 'm:n':3}
        dtyp = [('e1','i4'),('e2','i4'),('e3','i2'),('n', 'i1')]
        conv = {0: int, 1: int, 2: int, 3: lambda r: dmap[r.decode()]}
        test = np.recfromcsv(TextIO(dstr,), dtype=dtyp, delimiter=',',
                             names=None, converters=conv)
        control = np.rec.array([[1,5,-1,0], [2,8,-1,1], [3,3,-2,3]], dtype=dtyp)
        assert_equal(test, control)
        dtyp = [('e1','i4'),('e2','i4'),('n', 'i1')]
        test = np.recfromcsv(TextIO(dstr,), dtype=dtyp, delimiter=',',
                             usecols=(0,1,3), names=None, converters=conv)
        control = np.rec.array([[1,5,0], [2,8,1], [3,3,3]], dtype=dtyp)
        assert_equal(test, control) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:16,代碼來源:test_io.py

示例7: test_recfromcsv

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import recfromcsv [as 別名]
def test_recfromcsv(self):
        #
        data = TextIO('A,B\n0,1\n2,3')
        kwargs = dict(missing_values="N/A", names=True, case_sensitive=True)
        test = np.recfromcsv(data, dtype=None, **kwargs)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('A', np.int), ('B', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,N/A')
        test = np.recfromcsv(data, dtype=None, usemask=True, **kwargs)
        control = ma.array([(0, 1), (2, -1)],
                           mask=[(False, False), (False, True)],
                           dtype=[('A', np.int), ('B', np.int)])
        assert_equal(test, control)
        assert_equal(test.mask, control.mask)
        assert_equal(test.A, [0, 2])
        #
        data = TextIO('A,B\n0,1\n2,3')
        test = np.recfromcsv(data, missing_values='N/A',)
        control = np.array([(0, 1), (2, 3)],
                           dtype=[('a', np.int), ('b', np.int)])
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control)
        #
        data = TextIO('A,B\n0,1\n2,3')
        dtype = [('a', np.int), ('b', np.float)]
        test = np.recfromcsv(data, missing_values='N/A', dtype=dtype)
        control = np.array([(0, 1), (2, 3)],
                           dtype=dtype)
        self.assertTrue(isinstance(test, np.recarray))
        assert_equal(test, control) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:35,代碼來源:test_io.py

示例8: load

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import recfromcsv [as 別名]
def load(f):
    r"""Load a data file located in the data directory.

    Parameters
    ----------
    f : string
        File name.

    Returns
    -------
    x : array like
        Data loaded from permute.data_dir.
    """
    return np.recfromcsv(_os.path.join(data_dir, f), delimiter=",", encoding=None) 
開發者ID:statlab,項目名稱:permute,代碼行數:16,代碼來源:__init__.py

示例9: _load_data

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import recfromcsv [as 別名]
def _load_data(filename):
    """
    Loads data from csv, where the first column has the measurement date and all the other columns additional data
    :return: Rec-Array with date as a first column holding datetimes
    """
    def str2date(s):
        """Converts a string to a datetime"""
        return datetime.strptime(s.decode(), '%Y-%m-%d %H:%M:%S')
    # Load the data
    return np.recfromcsv(filename, converters={0: str2date}, comments='#') 
開發者ID:thouska,項目名稱:spotpy,代碼行數:12,代碼來源:spot_setup_cmf1d.py


注:本文中的numpy.recfromcsv方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。