Python get column index
10 Python code examples are found related to "
get column index".
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.
Example 1
Source File: facets_reformat_correctChromName.py From NGS-pipe with Apache License 2.0 | 6 votes |
def getColumnIndex(firstInputLine): firstLineSplit = firstInputLine.strip().split('\t') index_chrom = -1 index_start = -1 index_stop = -1 for pos in range(0,len(firstLineSplit)): if args.colName_chrom == firstLineSplit[pos]: index_chrom = pos continue if args.colName_start == firstLineSplit[pos]: index_start = pos continue if args.colName_stop == firstLineSplit[pos]: index_stop = pos continue if (index_chrom == -1) or (index_start == -1) or (index_stop == -1): print("Error! Did not find all columns matching the input parameteres in input header: \n%s." %(firstInputLine)) sys.exit(1) return (index_chrom, index_start, index_stop)
Example 2
Source File: error_table.py From VerifAI with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_column_by_index(self, index): if isinstance(index, int): index = list([index]) if len(index) < 1: print("No indices provided: returning all samples") elif max(index) >= len(self.table.columns): for i in index: if i >= len(self.table.columns): index.remove(i) print("Tried to access index not in error table") if len(self.table) > 0: names_index = self.table.columns[index] return self.table[names_index] else: print("No entries in error table yet") return None
Example 3
Source File: _pandas_helpers.py From python-bigquery with Apache License 2.0 | 6 votes |
def get_column_or_index(dataframe, name): """Return a column or index as a pandas series.""" if name in dataframe.columns: return dataframe[name].reset_index(drop=True) if isinstance(dataframe.index, pandas.MultiIndex): if name in dataframe.index.names: return ( dataframe.index.get_level_values(name) .to_series() .reset_index(drop=True) ) else: if name == dataframe.index.name: return dataframe.index.to_series().reset_index(drop=True) raise ValueError("column or index '{}' not found.".format(name))
Example 4
Source File: beautifultable.py From beautifultable with MIT License | 6 votes |
def get_column_index(self, header): """Get index of a column from it's header. Parameters ---------- header: str header of the column. Raises ------ ValueError: If no column could be found corresponding to `header`. """ try: index = self._column_headers.index(header) return index except ValueError: raise_suppressed( KeyError( ("'{}' is not a header for any " "column").format(header) ) )
Example 5
Source File: reportMetrics.py From InsightAgent with Apache License 2.0 | 5 votes |
def get_index_for_column_name(col_name): if col_name == "CPU": return 1 elif col_name == "DiskRead" or col_name == "DiskWrite": return 2 elif col_name == "DiskUsed": return 3 elif col_name == "NetworkIn" or col_name == "NetworkOut": return 4 elif col_name == "MemUsed": return 5
Example 6
Source File: views.py From InvenTree with MIT License | 5 votes |
def getColumnIndex(self, name): """ Return the index of the column with the given name. It named column is not found, return -1 """ try: idx = list(self.column_selections.values()).index(name) except ValueError: idx = -1 return idx
Example 7
Source File: source.py From blackmamba with MIT License | 5 votes |
def get_column_index(): text = editor.get_text() if text is None: return None col = 0 index = editor.get_selection()[0] while index > 0: if text[index - 1] == '\n': break index -= 1 col += 1 return col
Example 8
Source File: utils.py From esdc-ce with Apache License 2.0 | 5 votes |
def get_column_index(self, value): for row in self.HEADER_MAP: if value in row: return row[0] raise ValueError('Could not find %s in HEADER_MAP' % value)
Example 9
Source File: ObjectListView.py From bookhub with MIT License | 5 votes |
def GetPrimaryColumnIndex(self): """ Return the index of the primary column. Returns -1 when there is no primary column. The primary column is the first column given by the user. This column is edited when F2 is pressed. """ for (i, x) in enumerate(self.columns): if not x.isInternal: return i return -1
Example 10
Source File: utils.py From sklearn-onnx with MIT License | 4 votes |
def get_column_index(i, inputs): """ Returns a tuples (variable index, column index in that variable). The function has two different behaviours, one when *i* (column index) is an integer, another one when *i* is a string (column name). If *i* is a string, the function looks for input name with this name and returns (index, 0). If *i* is an integer, let's assume first we have two inputs *I0 = FloatTensorType([None, 2])* and *I1 = FloatTensorType([None, 3])*, in this case, here are the results: :: get_column_index(0, inputs) -> (0, 0) get_column_index(1, inputs) -> (0, 1) get_column_index(2, inputs) -> (1, 0) get_column_index(3, inputs) -> (1, 1) get_column_index(4, inputs) -> (1, 2) """ if isinstance(i, int): if i == 0: # Useful shortcut, skips the case when end is None # (unknown dimension) return 0, 0 vi = 0 pos = 0 end = (inputs[0].type.shape[1] if isinstance(inputs[0].type, TensorType) else 1) if end is None: raise RuntimeError("Cannot extract a specific column {0} when " "one input ('{1}') has unknown " "dimension.".format(i, inputs[0])) while True: if pos <= i < end: return (vi, i - pos) vi += 1 pos = end if vi >= len(inputs): import pprint raise RuntimeError( "Input {} (i={}, end={}) is not available in\n{}".format( vi, i, end, pprint.pformat(inputs))) rel_end = (inputs[vi].type.shape[1] if isinstance(inputs[vi].type, TensorType) else 1) if rel_end is None: raise RuntimeError("Cannot extract a specific column {0} when " "one input ('{1}') has unknown " "dimension.".format(i, inputs[vi])) end += rel_end else: for ind, inp in enumerate(inputs): if inp.onnx_name == i: return ind, 0 raise RuntimeError("Unable to find column name '{0}'".format(i))