当前位置: 首页>>代码示例>>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;未经允许,请勿转载。