本文整理匯總了Python中pandas.core.common.flatten方法的典型用法代碼示例。如果您正苦於以下問題:Python common.flatten方法的具體用法?Python common.flatten怎麽用?Python common.flatten使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pandas.core.common
的用法示例。
在下文中一共展示了common.flatten方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _align
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def _align(terms):
"""Align a set of terms"""
try:
# flatten the parse tree (a nested list, really)
terms = list(com.flatten(terms))
except TypeError:
# can't iterate so it must just be a constant or single variable
if isinstance(terms.value, pd.core.generic.NDFrame):
typ = type(terms.value)
return typ, _zip_axes_from_type(typ, terms.value.axes)
return np.result_type(terms.type), None
# if all resolved variables are numeric scalars
if all(term.isscalar for term in terms):
return np.result_type(*(term.value for term in terms)).type, None
# perform the main alignment
typ, axes = _align_core(terms)
return typ, axes
示例2: get_attr_values
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def get_attr_values(self, attrlist):
"""
Get value corresponding to each given attribute.
:param str | Iterable[str] attrlist: names of attributes to
retrieve values for
:return list | NoneType: value (or empty string) corresponding to
each named attribute; null if this Sample's value for the
attribute given by the argument to the "attrlist" parameter is
empty/null, or if this Sample lacks the indicated attribute
"""
from pandas.core.common import flatten
# If attribute is None, then value is also None.
if not attrlist:
return None
if not isinstance(attrlist, list):
attrlist = [attrlist]
# Strings contained here are appended later so shouldn't be null.
return list(flatten([getattr(self, attr, "") for attr in attrlist]))
示例3: __init__
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def __init__(self, where, queryables=None, encoding=None, scope_level=0):
where = _validate_where(where)
self.encoding = encoding
self.condition = None
self.filter = None
self.terms = None
self._visitor = None
# capture the environment if needed
local_dict = DeepChainMap()
if isinstance(where, Expr):
local_dict = where.env.scope
where = where.expr
elif isinstance(where, (list, tuple)):
for idx, w in enumerate(where):
if isinstance(w, Expr):
local_dict = w.env.scope
else:
w = _validate_where(w)
where[idx] = w
where = ' & '.join(map('({})'.format, com.flatten(where))) # noqa
self.expr = where
self.env = Scope(scope_level + 1, local_dict=local_dict)
if queryables is not None and isinstance(self.expr, string_types):
self.env.queryables.update(queryables)
self._visitor = ExprVisitor(self.env, queryables=queryables,
parser='pytables', engine='pytables',
encoding=encoding)
self.terms = self.parse()
示例4: names
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def names(self):
"""Get the names in an expression"""
if is_term(self.terms):
return frozenset([self.terms.name])
return frozenset(term.name for term in com.flatten(self.terms))
示例5: return_type
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def return_type(self):
# clobber types to bool if the op is a boolean operator
if self.op in (_cmp_ops_syms + _bool_ops_syms):
return np.bool_
return _result_type_many(*(term.type for term in com.flatten(self)))
示例6: operand_types
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def operand_types(self):
return frozenset(term.type for term in com.flatten(self))
示例7: __init__
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def __init__(self, lhs, rhs, truediv, *args, **kwargs):
super(Div, self).__init__('/', lhs, rhs, *args, **kwargs)
if not isnumeric(lhs.return_type) or not isnumeric(rhs.return_type):
raise TypeError("unsupported operand type(s) for {0}:"
" '{1}' and '{2}'".format(self.op,
lhs.return_type,
rhs.return_type))
if truediv or PY3:
# do not upcast float32s to float64 un-necessarily
acceptable_dtypes = [np.float32, np.float_]
_cast_inplace(com.flatten(self), acceptable_dtypes, np.float_)
示例8: return_type
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def return_type(self):
# clobber types to bool if the op is a boolean operator
if self.op in (_cmp_ops_syms + _bool_ops_syms):
return np.bool_
return np.result_type(*(term.type for term in com.flatten(self)))
示例9: __init__
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def __init__(self, lhs, rhs, truediv=True, *args, **kwargs):
super(Div, self).__init__('/', lhs, rhs, *args, **kwargs)
if truediv or PY3:
_cast_inplace(com.flatten(self), np.float_)
示例10: setwrap
# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import flatten [as 別名]
def setwrap(value: Any) -> Set[str]:
"""
Returns a flattened and stringified set from the given object or iterable.
For use in public functions which accept argmuents or kwargs that can be
one object or a list of objects.
"""
return set(map(str, set(flatten([value]))))