Python pandas.core.common._try_sort() Examples
The following are 11
code examples of pandas.core.common._try_sort().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pandas.core.common
, or try the search function
.
Example #1
Source File: _core.py From vnpy_crypto with MIT License | 6 votes |
def _iter_data(self, data=None, keep_index=False, fillna=None): if data is None: data = self.data if fillna is not None: data = data.fillna(fillna) # TODO: unused? # if self.sort_columns: # columns = com._try_sort(data.columns) # else: # columns = data.columns for col, values in data.iteritems(): if keep_index is True: yield col, values else: yield col, values.values
Example #2
Source File: api.py From vnpy_crypto with MIT License | 6 votes |
def _sanitize_and_check(indexes): kinds = list({type(index) for index in indexes}) if list in kinds: if len(kinds) > 1: indexes = [Index(com._try_sort(x)) if not isinstance(x, Index) else x for x in indexes] kinds.remove(list) else: return indexes, 'list' if len(kinds) > 1 or Index not in kinds: return indexes, 'special' else: return indexes, 'array'
Example #3
Source File: plotting.py From Computable with MIT License | 6 votes |
def _iter_data(self): from pandas.core.frame import DataFrame if isinstance(self.data, (Series, np.ndarray)): yield self.label, np.asarray(self.data) elif isinstance(self.data, DataFrame): df = self.data if self.sort_columns: columns = com._try_sort(df.columns) else: columns = df.columns for col in columns: # # is this right? # empty = df[col].count() == 0 # values = df[col].values if not empty else np.zeros(len(df)) values = df[col].values yield col, values
Example #4
Source File: index.py From Computable with MIT License | 6 votes |
def _sanitize_and_check(indexes): kinds = list(set([type(index) for index in indexes])) if list in kinds: if len(kinds) > 1: indexes = [Index(com._try_sort(x)) if not isinstance(x, Index) else x for x in indexes] kinds.remove(list) else: return indexes, 'list' if len(kinds) > 1 or Index not in kinds: return indexes, 'special' else: return indexes, 'array'
Example #5
Source File: _core.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _iter_data(self, data=None, keep_index=False, fillna=None): if data is None: data = self.data if fillna is not None: data = data.fillna(fillna) # TODO: unused? # if self.sort_columns: # columns = _try_sort(data.columns) # else: # columns = data.columns for col, values in data.iteritems(): if keep_index is True: yield col, values else: yield col, values.values
Example #6
Source File: api.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _sanitize_and_check(indexes): kinds = list(set([type(index) for index in indexes])) if list in kinds: if len(kinds) > 1: indexes = [Index(com._try_sort(x)) if not isinstance(x, Index) else x for x in indexes] kinds.remove(list) else: return indexes, 'list' if len(kinds) > 1 or Index not in kinds: return indexes, 'special' else: return indexes, 'array'
Example #7
Source File: _core.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def _iter_data(self, data=None, keep_index=False, fillna=None): if data is None: data = self.data if fillna is not None: data = data.fillna(fillna) # TODO: unused? # if self.sort_columns: # columns = _try_sort(data.columns) # else: # columns = data.columns for col, values in data.iteritems(): if keep_index is True: yield col, values else: yield col, values.values
Example #8
Source File: api.py From elasticintel with GNU General Public License v3.0 | 6 votes |
def _sanitize_and_check(indexes): kinds = list(set([type(index) for index in indexes])) if list in kinds: if len(kinds) > 1: indexes = [Index(com._try_sort(x)) if not isinstance(x, Index) else x for x in indexes] kinds.remove(list) else: return indexes, 'list' if len(kinds) > 1 or Index not in kinds: return indexes, 'special' else: return indexes, 'array'
Example #9
Source File: _core.py From twitter-stock-recommendation with MIT License | 6 votes |
def _iter_data(self, data=None, keep_index=False, fillna=None): if data is None: data = self.data if fillna is not None: data = data.fillna(fillna) # TODO: unused? # if self.sort_columns: # columns = com._try_sort(data.columns) # else: # columns = data.columns for col, values in data.iteritems(): if keep_index is True: yield col, values else: yield col, values.values
Example #10
Source File: frame.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def _init_dict(self, data, index, columns, dtype=None): # pre-filter out columns if we passed it if columns is not None: columns = _ensure_index(columns) data = dict((k, v) for k, v in compat.iteritems(data) if k in columns) else: columns = Index(_try_sort(list(data.keys()))) if index is None: index = extract_index(list(data.values())) sp_maker = lambda x: SparseArray(x, kind=self._default_kind, fill_value=self._default_fill_value, copy=True, dtype=dtype) sdict = {} for k, v in compat.iteritems(data): if isinstance(v, Series): # Force alignment, no copy necessary if not v.index.equals(index): v = v.reindex(index) if not isinstance(v, SparseSeries): v = sp_maker(v.values) elif isinstance(v, SparseArray): v = v.copy() else: if isinstance(v, dict): v = [v.get(i, np.nan) for i in index] v = sp_maker(v) sdict[k] = v # TODO: figure out how to handle this case, all nan's? # add in any other columns we want to have (completeness) nan_arr = np.empty(len(index), dtype='float64') nan_arr.fill(np.nan) nan_arr = sp_maker(nan_arr) sdict.update((c, nan_arr) for c in columns if c not in sdict) return to_manager(sdict, columns, index)
Example #11
Source File: frame.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def _init_dict(self, data, index, columns, dtype=None): # pre-filter out columns if we passed it if columns is not None: columns = _ensure_index(columns) data = dict((k, v) for k, v in compat.iteritems(data) if k in columns) else: columns = Index(_try_sort(list(data.keys()))) if index is None: index = extract_index(list(data.values())) sp_maker = lambda x: SparseArray(x, kind=self._default_kind, fill_value=self._default_fill_value, copy=True, dtype=dtype) sdict = {} for k, v in compat.iteritems(data): if isinstance(v, Series): # Force alignment, no copy necessary if not v.index.equals(index): v = v.reindex(index) if not isinstance(v, SparseSeries): v = sp_maker(v.values) elif isinstance(v, SparseArray): v = v.copy() else: if isinstance(v, dict): v = [v.get(i, np.nan) for i in index] v = sp_maker(v) sdict[k] = v # TODO: figure out how to handle this case, all nan's? # add in any other columns we want to have (completeness) nan_arr = np.empty(len(index), dtype='float64') nan_arr.fill(np.nan) nan_arr = sp_maker(nan_arr) sdict.update((c, nan_arr) for c in columns if c not in sdict) return to_manager(sdict, columns, index)