tab-dataset.tab_dataset.field_interface
The field_interface module is part of the tab-dataset package.
It contains the classes FieldInterface for Field entities.
For more information, see the user guide or the github repository.
1# -*- coding: utf-8 -*- 2""" 3The `field_interface` module is part of the `tab-dataset` package. 4 5It contains the classes `FieldInterface` for Field entities. 6 7For more information, see the 8[user guide](https://loco-philippe.github.io/tab-dataset/docs/user_guide.html) 9or the [github repository](https://github.com/loco-philippe/tab-dataset). 10""" 11# %% declarations 12import json 13import datetime 14import numpy as np 15import pandas as pd 16 17from json_ntv.ntv import NtvSingle, NtvList 18from json_ntv.ntv_util import NtvUtil 19from tab_dataset.cfield import FieldError, Cutil, identity 20 21 22class CborDecoder(json.JSONDecoder): 23 ''' Cbor extension for integer keys (codification keys)''' 24 25 def __init__(self): 26 json.JSONDecoder.__init__(self, object_hook=self.codecbor) 27 28 def codecbor(self, dic): 29 ''' convert dict keys into integer and return new dict''' 30 dic2 = {} 31 for key, val in dic.items(): 32 try: 33 key2 = int(key) 34 except: 35 key2 = key 36 dic2[key2] = val 37 return dic2 38 39 40class FieldEncoder(json.JSONEncoder): 41 """new json encoder for Field and Dataset""" 42 43 def default(self, o): 44 if isinstance(o, datetime.datetime): 45 return o.isoformat() 46 option = {'encoded': False, 'format': 'json'} 47 if o.__class__.__name__ in ('Dataset', 'TimeSlot', 'Ndataset', 'Sdataset'): 48 return o.json(**option) 49 # if issubclass(o.__class__, ESValue): 50 # return o.json(**option) 51 try: 52 return o.to_json(**option) 53 except: 54 try: 55 return o.__to_json__() 56 except: 57 return json.JSONEncoder.default(self, o) 58 59 60class FieldInterface: 61 '''this class includes Field methods : 62 63 - `FieldInterface.json` 64 - `FieldInterface.to_obj` 65 - `FieldInterface.to_dict_obj` 66 - `FieldInterface.to_numpy` 67 - `FieldInterface.to_pandas` 68 - `FieldInterface.vlist` 69 - `FieldInterface.v_name` 70 - `FieldInterface.vSimple` 71 ''' 72 73 def to_numpy(self, func=None, codec=False, npdtype=None, **kwargs): 74 ''' 75 Transform Field in a Numpy array. 76 77 *Parameters* 78 79 - **func** : function (default None) - function to apply for each value of the Field. 80 If func is the 'index' string, values are replaced by raw values. 81 - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None) 82 - **kwargs** : parameters to apply to the func function 83 84 *Returns* : Numpy Array''' 85 return self.to_pandas(func=func, codec=codec, npdtype=npdtype, numpy=True, **kwargs) 86 87 def to_ntv(self, modecodec='optimize', codecval=False, def_type=None, 88 keys=None, parent=None, name=True, coef=None): 89 '''Return a Ntv field value 90 91 *Parameters (kwargs)* 92 93 - **modecodec** : string (default 'optimize') - if 'full', index is with a full codec 94 if 'default' index has keys, if 'optimize' keys are optimized, 95 - **codecval** : boolean (default False) - if True, only list of codec values is included 96 - **def_type** : string (default 'json') - default ntv_type for NtvList or NtvSet 97 - **name** : boolean (default True) - if False, index name are not included 98 - **keys** : list (default None) - used only with 'optimize' mode 99 - **parent** : int or str (default None) - used only with 'optimize' mode 100 101 *Returns* : Ntv object''' 102 leng = len(self) 103 codec = self.i_to_n(self.codec) 104 decode_name, decode_type, sep = NtvUtil.from_obj_name(self.name) 105 decode_name = decode_name if sep == '::' else self.name 106 def_type = decode_type if sep == '::' and decode_type else def_type 107 def_type = codec[0].ntv_type if not def_type and codec else def_type 108 idxname = None if decode_name == '$default' or not name else decode_name 109 if leng == 1 or len(codec) == 1 and modecodec != 'full': 110 return NtvSingle(codec[0].ntv_value, idxname, codec[0].ntv_type) 111 if codecval or modecodec == 'nokeys': 112 return NtvList(codec, idxname, ntv_type=def_type) 113 if len(codec) == leng or modecodec == 'full': 114 return NtvList(self.values, idxname, ntv_type=def_type) 115 if modecodec == 'default': 116 return NtvList([NtvList(codec, ntv_type=def_type), 117 NtvList(self.keys, ntv_type='json')], idxname, ntv_type='json') 118 if coef: 119 return NtvList([NtvList(codec, ntv_type=def_type), 120 NtvList([coef], ntv_type='json')], idxname, ntv_type='json') 121 if modecodec == 'optimize': 122 ntv_value = [NtvList(codec, ntv_type=def_type)] 123 if not parent is None: 124 ntv_value.append(NtvSingle(parent, ntv_type='json')) 125 if keys: 126 ntv_value.append(NtvList(keys, ntv_type='json')) 127 elif parent is None: 128 ntv_value.append(NtvList(self.keys, ntv_type='json')) 129 return NtvList(ntv_value, idxname, ntv_type='json') 130 return None 131 132 def to_pandas(self, func=None, codec=False, npdtype=None, 133 series=True, index=True, numpy=False, **kwargs): 134 ''' 135 Transform Field in a Pandas Series, Pandas DataFrame or Numpy array. 136 137 *Parameters* 138 139 - **func** : function (default None) - function to apply for each value of the Field. 140 If func is the 'index' string, values are replaced by raw values. 141 - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None) 142 - **series** : boolean (default True) - if True, return a Series. 143 If False return a DataFrame 144 - **index** : boolean (default True) - if True, index is keys. 145 - **numpy** : boolean (default False) - if True, return a Numpy array. 146 - **kwargs** : parameters to apply to the func function 147 148 *Returns* : Pandas Series, Pandas DataFrame, Numpy Array''' 149 if len(self) == 0: 150 raise FieldError("Dataset is empty") 151 if npdtype: 152 npdtype = np.dtype(npdtype) 153 else: 154 npdtype = 'object' 155 if func is None: 156 func = identity 157 if func == 'index': 158 return np.array(list(range(len(self)))) 159 if not codec: 160 values = Cutil.funclist(self.values, func, **kwargs) 161 else: 162 values = Cutil.funclist(self._codec, func, **kwargs) 163 npdtype1 = npdtype 164 if isinstance(values[0], (datetime.datetime)): 165 npdtype1 = np.datetime64 166 pdindex = None 167 if index: 168 pdindex = self._keys 169 try: 170 if numpy: 171 return np.array(values, dtype=npdtype1) 172 if series: 173 return pd.Series(values, dtype=npdtype1, 174 index=pdindex, name=self.name) 175 return pd.DataFrame(pd.Series(values, dtype=npdtype1, 176 index=pdindex, name=self.name)) 177 except: 178 if numpy: 179 return np.array(values, dtype=npdtype) 180 if series: 181 return pd.Series(values, dtype=npdtype, 182 index=pdindex, name=self.name) 183 return pd.DataFrame(pd.Series(values, dtype=npdtype, 184 index=pdindex, name=self.name)) 185 186 def vlist(self, func, *args, extern=True, **kwargs): 187 ''' 188 Apply a function to values and return the result. 189 190 *Parameters* 191 192 - **func** : function - function to apply to values 193 - **args, kwargs** : parameters for the function 194 - **extern** : if True, the function is apply to external values, else internal 195 196 *Returns* : list of func result''' 197 if extern: 198 return Cutil.funclist(self.val, func, *args, **kwargs) 199 return Cutil.funclist(self.values, func, *args, **kwargs) 200 201 def v_name(self): 202 '''Return the list of name of values''' 203 return [self.i_to_name(val) for val in self.values] 204 205 """def vSimple(self, string=False): 206 ''' 207 Apply a vSimple function to values and return the result. 208 209 *Parameters* 210 211 - **string** : boolean(default False) - if True the values returned are string 212 213 *Returns* : list of vSimple values (string or not)''' 214 if string: 215 return json.dumps([util.cast(val, 'simple', string=string) for val in self.values], 216 cls=ESValueEncoder) 217 return [util.cast(val, 'simple', string=string) for val in self.values]"""
23class CborDecoder(json.JSONDecoder): 24 ''' Cbor extension for integer keys (codification keys)''' 25 26 def __init__(self): 27 json.JSONDecoder.__init__(self, object_hook=self.codecbor) 28 29 def codecbor(self, dic): 30 ''' convert dict keys into integer and return new dict''' 31 dic2 = {} 32 for key, val in dic.items(): 33 try: 34 key2 = int(key) 35 except: 36 key2 = key 37 dic2[key2] = val 38 return dic2
Cbor extension for integer keys (codification keys)
object_hook, if specified, will be called with the result
of every JSON object decoded and its return value will be used in
place of the given dict. This can be used to provide custom
deserializations (e.g. to support JSON-RPC class hinting).
object_pairs_hook, if specified will be called with the result of
every JSON object decoded with an ordered list of pairs. The return
value of object_pairs_hook will be used instead of the dict.
This feature can be used to implement custom decoders.
If object_hook is also defined, the object_pairs_hook takes
priority.
parse_float, if specified, will be called with the string
of every JSON float to be decoded. By default this is equivalent to
float(num_str). This can be used to use another datatype or parser
for JSON floats (e.g. decimal.Decimal).
parse_int, if specified, will be called with the string
of every JSON int to be decoded. By default this is equivalent to
int(num_str). This can be used to use another datatype or parser
for JSON integers (e.g. float).
parse_constant, if specified, will be called with one of the
following strings: -Infinity, Infinity, NaN.
This can be used to raise an exception if invalid JSON numbers
are encountered.
If strict is false (true is the default), then control
characters will be allowed inside strings. Control characters in
this context are those with character codes in the 0-31 range,
including '\t' (tab), '\n', '\r' and '\0'.
29 def codecbor(self, dic): 30 ''' convert dict keys into integer and return new dict''' 31 dic2 = {} 32 for key, val in dic.items(): 33 try: 34 key2 = int(key) 35 except: 36 key2 = key 37 dic2[key2] = val 38 return dic2
convert dict keys into integer and return new dict
Inherited Members
- json.decoder.JSONDecoder
- decode
- raw_decode
41class FieldEncoder(json.JSONEncoder): 42 """new json encoder for Field and Dataset""" 43 44 def default(self, o): 45 if isinstance(o, datetime.datetime): 46 return o.isoformat() 47 option = {'encoded': False, 'format': 'json'} 48 if o.__class__.__name__ in ('Dataset', 'TimeSlot', 'Ndataset', 'Sdataset'): 49 return o.json(**option) 50 # if issubclass(o.__class__, ESValue): 51 # return o.json(**option) 52 try: 53 return o.to_json(**option) 54 except: 55 try: 56 return o.__to_json__() 57 except: 58 return json.JSONEncoder.default(self, o)
new json encoder for Field and Dataset
44 def default(self, o): 45 if isinstance(o, datetime.datetime): 46 return o.isoformat() 47 option = {'encoded': False, 'format': 'json'} 48 if o.__class__.__name__ in ('Dataset', 'TimeSlot', 'Ndataset', 'Sdataset'): 49 return o.json(**option) 50 # if issubclass(o.__class__, ESValue): 51 # return o.json(**option) 52 try: 53 return o.to_json(**option) 54 except: 55 try: 56 return o.__to_json__() 57 except: 58 return json.JSONEncoder.default(self, o)
Implement this method in a subclass such that it returns
a serializable object for o, or calls the base implementation
(to raise a TypeError).
For example, to support arbitrary iterators, you could implement default like this::
def default(self, o):
try:
iterable = iter(o)
except TypeError:
pass
else:
return list(iterable)
# Let the base class default method raise the TypeError
return JSONEncoder.default(self, o)
Inherited Members
- json.encoder.JSONEncoder
- JSONEncoder
- encode
- iterencode
61class FieldInterface: 62 '''this class includes Field methods : 63 64 - `FieldInterface.json` 65 - `FieldInterface.to_obj` 66 - `FieldInterface.to_dict_obj` 67 - `FieldInterface.to_numpy` 68 - `FieldInterface.to_pandas` 69 - `FieldInterface.vlist` 70 - `FieldInterface.v_name` 71 - `FieldInterface.vSimple` 72 ''' 73 74 def to_numpy(self, func=None, codec=False, npdtype=None, **kwargs): 75 ''' 76 Transform Field in a Numpy array. 77 78 *Parameters* 79 80 - **func** : function (default None) - function to apply for each value of the Field. 81 If func is the 'index' string, values are replaced by raw values. 82 - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None) 83 - **kwargs** : parameters to apply to the func function 84 85 *Returns* : Numpy Array''' 86 return self.to_pandas(func=func, codec=codec, npdtype=npdtype, numpy=True, **kwargs) 87 88 def to_ntv(self, modecodec='optimize', codecval=False, def_type=None, 89 keys=None, parent=None, name=True, coef=None): 90 '''Return a Ntv field value 91 92 *Parameters (kwargs)* 93 94 - **modecodec** : string (default 'optimize') - if 'full', index is with a full codec 95 if 'default' index has keys, if 'optimize' keys are optimized, 96 - **codecval** : boolean (default False) - if True, only list of codec values is included 97 - **def_type** : string (default 'json') - default ntv_type for NtvList or NtvSet 98 - **name** : boolean (default True) - if False, index name are not included 99 - **keys** : list (default None) - used only with 'optimize' mode 100 - **parent** : int or str (default None) - used only with 'optimize' mode 101 102 *Returns* : Ntv object''' 103 leng = len(self) 104 codec = self.i_to_n(self.codec) 105 decode_name, decode_type, sep = NtvUtil.from_obj_name(self.name) 106 decode_name = decode_name if sep == '::' else self.name 107 def_type = decode_type if sep == '::' and decode_type else def_type 108 def_type = codec[0].ntv_type if not def_type and codec else def_type 109 idxname = None if decode_name == '$default' or not name else decode_name 110 if leng == 1 or len(codec) == 1 and modecodec != 'full': 111 return NtvSingle(codec[0].ntv_value, idxname, codec[0].ntv_type) 112 if codecval or modecodec == 'nokeys': 113 return NtvList(codec, idxname, ntv_type=def_type) 114 if len(codec) == leng or modecodec == 'full': 115 return NtvList(self.values, idxname, ntv_type=def_type) 116 if modecodec == 'default': 117 return NtvList([NtvList(codec, ntv_type=def_type), 118 NtvList(self.keys, ntv_type='json')], idxname, ntv_type='json') 119 if coef: 120 return NtvList([NtvList(codec, ntv_type=def_type), 121 NtvList([coef], ntv_type='json')], idxname, ntv_type='json') 122 if modecodec == 'optimize': 123 ntv_value = [NtvList(codec, ntv_type=def_type)] 124 if not parent is None: 125 ntv_value.append(NtvSingle(parent, ntv_type='json')) 126 if keys: 127 ntv_value.append(NtvList(keys, ntv_type='json')) 128 elif parent is None: 129 ntv_value.append(NtvList(self.keys, ntv_type='json')) 130 return NtvList(ntv_value, idxname, ntv_type='json') 131 return None 132 133 def to_pandas(self, func=None, codec=False, npdtype=None, 134 series=True, index=True, numpy=False, **kwargs): 135 ''' 136 Transform Field in a Pandas Series, Pandas DataFrame or Numpy array. 137 138 *Parameters* 139 140 - **func** : function (default None) - function to apply for each value of the Field. 141 If func is the 'index' string, values are replaced by raw values. 142 - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None) 143 - **series** : boolean (default True) - if True, return a Series. 144 If False return a DataFrame 145 - **index** : boolean (default True) - if True, index is keys. 146 - **numpy** : boolean (default False) - if True, return a Numpy array. 147 - **kwargs** : parameters to apply to the func function 148 149 *Returns* : Pandas Series, Pandas DataFrame, Numpy Array''' 150 if len(self) == 0: 151 raise FieldError("Dataset is empty") 152 if npdtype: 153 npdtype = np.dtype(npdtype) 154 else: 155 npdtype = 'object' 156 if func is None: 157 func = identity 158 if func == 'index': 159 return np.array(list(range(len(self)))) 160 if not codec: 161 values = Cutil.funclist(self.values, func, **kwargs) 162 else: 163 values = Cutil.funclist(self._codec, func, **kwargs) 164 npdtype1 = npdtype 165 if isinstance(values[0], (datetime.datetime)): 166 npdtype1 = np.datetime64 167 pdindex = None 168 if index: 169 pdindex = self._keys 170 try: 171 if numpy: 172 return np.array(values, dtype=npdtype1) 173 if series: 174 return pd.Series(values, dtype=npdtype1, 175 index=pdindex, name=self.name) 176 return pd.DataFrame(pd.Series(values, dtype=npdtype1, 177 index=pdindex, name=self.name)) 178 except: 179 if numpy: 180 return np.array(values, dtype=npdtype) 181 if series: 182 return pd.Series(values, dtype=npdtype, 183 index=pdindex, name=self.name) 184 return pd.DataFrame(pd.Series(values, dtype=npdtype, 185 index=pdindex, name=self.name)) 186 187 def vlist(self, func, *args, extern=True, **kwargs): 188 ''' 189 Apply a function to values and return the result. 190 191 *Parameters* 192 193 - **func** : function - function to apply to values 194 - **args, kwargs** : parameters for the function 195 - **extern** : if True, the function is apply to external values, else internal 196 197 *Returns* : list of func result''' 198 if extern: 199 return Cutil.funclist(self.val, func, *args, **kwargs) 200 return Cutil.funclist(self.values, func, *args, **kwargs) 201 202 def v_name(self): 203 '''Return the list of name of values''' 204 return [self.i_to_name(val) for val in self.values] 205 206 """def vSimple(self, string=False): 207 ''' 208 Apply a vSimple function to values and return the result. 209 210 *Parameters* 211 212 - **string** : boolean(default False) - if True the values returned are string 213 214 *Returns* : list of vSimple values (string or not)''' 215 if string: 216 return json.dumps([util.cast(val, 'simple', string=string) for val in self.values], 217 cls=ESValueEncoder) 218 return [util.cast(val, 'simple', string=string) for val in self.values]"""
this class includes Field methods :
FieldInterface.jsonFieldInterface.to_objFieldInterface.to_dict_objFieldInterface.to_numpyFieldInterface.to_pandasFieldInterface.vlistFieldInterface.v_nameFieldInterface.vSimple
74 def to_numpy(self, func=None, codec=False, npdtype=None, **kwargs): 75 ''' 76 Transform Field in a Numpy array. 77 78 *Parameters* 79 80 - **func** : function (default None) - function to apply for each value of the Field. 81 If func is the 'index' string, values are replaced by raw values. 82 - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None) 83 - **kwargs** : parameters to apply to the func function 84 85 *Returns* : Numpy Array''' 86 return self.to_pandas(func=func, codec=codec, npdtype=npdtype, numpy=True, **kwargs)
Transform Field in a Numpy array.
Parameters
- func : function (default None) - function to apply for each value of the Field. If func is the 'index' string, values are replaced by raw values.
- npdtype : string (default None) - numpy dtype for the Array ('object' if None)
- kwargs : parameters to apply to the func function
Returns : Numpy Array
88 def to_ntv(self, modecodec='optimize', codecval=False, def_type=None, 89 keys=None, parent=None, name=True, coef=None): 90 '''Return a Ntv field value 91 92 *Parameters (kwargs)* 93 94 - **modecodec** : string (default 'optimize') - if 'full', index is with a full codec 95 if 'default' index has keys, if 'optimize' keys are optimized, 96 - **codecval** : boolean (default False) - if True, only list of codec values is included 97 - **def_type** : string (default 'json') - default ntv_type for NtvList or NtvSet 98 - **name** : boolean (default True) - if False, index name are not included 99 - **keys** : list (default None) - used only with 'optimize' mode 100 - **parent** : int or str (default None) - used only with 'optimize' mode 101 102 *Returns* : Ntv object''' 103 leng = len(self) 104 codec = self.i_to_n(self.codec) 105 decode_name, decode_type, sep = NtvUtil.from_obj_name(self.name) 106 decode_name = decode_name if sep == '::' else self.name 107 def_type = decode_type if sep == '::' and decode_type else def_type 108 def_type = codec[0].ntv_type if not def_type and codec else def_type 109 idxname = None if decode_name == '$default' or not name else decode_name 110 if leng == 1 or len(codec) == 1 and modecodec != 'full': 111 return NtvSingle(codec[0].ntv_value, idxname, codec[0].ntv_type) 112 if codecval or modecodec == 'nokeys': 113 return NtvList(codec, idxname, ntv_type=def_type) 114 if len(codec) == leng or modecodec == 'full': 115 return NtvList(self.values, idxname, ntv_type=def_type) 116 if modecodec == 'default': 117 return NtvList([NtvList(codec, ntv_type=def_type), 118 NtvList(self.keys, ntv_type='json')], idxname, ntv_type='json') 119 if coef: 120 return NtvList([NtvList(codec, ntv_type=def_type), 121 NtvList([coef], ntv_type='json')], idxname, ntv_type='json') 122 if modecodec == 'optimize': 123 ntv_value = [NtvList(codec, ntv_type=def_type)] 124 if not parent is None: 125 ntv_value.append(NtvSingle(parent, ntv_type='json')) 126 if keys: 127 ntv_value.append(NtvList(keys, ntv_type='json')) 128 elif parent is None: 129 ntv_value.append(NtvList(self.keys, ntv_type='json')) 130 return NtvList(ntv_value, idxname, ntv_type='json') 131 return None
Return a Ntv field value
Parameters (kwargs)
- modecodec : string (default 'optimize') - if 'full', index is with a full codec if 'default' index has keys, if 'optimize' keys are optimized,
- codecval : boolean (default False) - if True, only list of codec values is included
- def_type : string (default 'json') - default ntv_type for NtvList or NtvSet
- name : boolean (default True) - if False, index name are not included
- keys : list (default None) - used only with 'optimize' mode
- parent : int or str (default None) - used only with 'optimize' mode
Returns : Ntv object
133 def to_pandas(self, func=None, codec=False, npdtype=None, 134 series=True, index=True, numpy=False, **kwargs): 135 ''' 136 Transform Field in a Pandas Series, Pandas DataFrame or Numpy array. 137 138 *Parameters* 139 140 - **func** : function (default None) - function to apply for each value of the Field. 141 If func is the 'index' string, values are replaced by raw values. 142 - **npdtype** : string (default None) - numpy dtype for the Array ('object' if None) 143 - **series** : boolean (default True) - if True, return a Series. 144 If False return a DataFrame 145 - **index** : boolean (default True) - if True, index is keys. 146 - **numpy** : boolean (default False) - if True, return a Numpy array. 147 - **kwargs** : parameters to apply to the func function 148 149 *Returns* : Pandas Series, Pandas DataFrame, Numpy Array''' 150 if len(self) == 0: 151 raise FieldError("Dataset is empty") 152 if npdtype: 153 npdtype = np.dtype(npdtype) 154 else: 155 npdtype = 'object' 156 if func is None: 157 func = identity 158 if func == 'index': 159 return np.array(list(range(len(self)))) 160 if not codec: 161 values = Cutil.funclist(self.values, func, **kwargs) 162 else: 163 values = Cutil.funclist(self._codec, func, **kwargs) 164 npdtype1 = npdtype 165 if isinstance(values[0], (datetime.datetime)): 166 npdtype1 = np.datetime64 167 pdindex = None 168 if index: 169 pdindex = self._keys 170 try: 171 if numpy: 172 return np.array(values, dtype=npdtype1) 173 if series: 174 return pd.Series(values, dtype=npdtype1, 175 index=pdindex, name=self.name) 176 return pd.DataFrame(pd.Series(values, dtype=npdtype1, 177 index=pdindex, name=self.name)) 178 except: 179 if numpy: 180 return np.array(values, dtype=npdtype) 181 if series: 182 return pd.Series(values, dtype=npdtype, 183 index=pdindex, name=self.name) 184 return pd.DataFrame(pd.Series(values, dtype=npdtype, 185 index=pdindex, name=self.name))
Transform Field in a Pandas Series, Pandas DataFrame or Numpy array.
Parameters
- func : function (default None) - function to apply for each value of the Field. If func is the 'index' string, values are replaced by raw values.
- npdtype : string (default None) - numpy dtype for the Array ('object' if None)
- series : boolean (default True) - if True, return a Series. If False return a DataFrame
- index : boolean (default True) - if True, index is keys.
- numpy : boolean (default False) - if True, return a Numpy array.
- kwargs : parameters to apply to the func function
Returns : Pandas Series, Pandas DataFrame, Numpy Array
187 def vlist(self, func, *args, extern=True, **kwargs): 188 ''' 189 Apply a function to values and return the result. 190 191 *Parameters* 192 193 - **func** : function - function to apply to values 194 - **args, kwargs** : parameters for the function 195 - **extern** : if True, the function is apply to external values, else internal 196 197 *Returns* : list of func result''' 198 if extern: 199 return Cutil.funclist(self.val, func, *args, **kwargs) 200 return Cutil.funclist(self.values, func, *args, **kwargs)
Apply a function to values and return the result.
Parameters
- func : function - function to apply to values
- args, kwargs : parameters for the function
- extern : if True, the function is apply to external values, else internal
Returns : list of func result