Every line of 'python read tsv' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
26 def load_tsv(): 27 import pandas as pd 28 29 print('loading with pandas') 30 31 filename = 'mat_cats.tsv' 32 tmp = pd.read_table(filename, sep='\t', index_col=[0,1], skipinitialspace=True, na_values='NaN', keep_default_na=False, usecols=range(12), skip_blank_lines=True) 33 34 # filename = 'mat_2cc_1rc.txt' 35 # tmp = pd.read_table(filename, index_col=[0,1], header=[0,1]) 36 37 mat = tmp.values 38 row_names = tmp.index.tolist() 39 col_names = tmp.columns.tolist() 40 41 print(mat) 42 print('\nrow_names') 43 print(row_names) 44 print(len(row_names)) 45 print('\ncol names') 46 print(col_names) 47 print(len(col_names))
52 def tsvreader(file): 53 reader = csv.reader(file, delimiter='\t') 54 for row in reader: 55 yield row
32 def parse_tsv(tsv_fpath): 33 """ Parse a tsv ';' seperated file which was downloaded from vizier 34 """ 35 out_dict = {'data_lists':{}, 36 'data_units_dict':{}} 37 icol_to_colname = {} 38 lines = open(tsv_fpath) 39 i_signif_line = 0 40 for line_raw in lines: 41 line = line_raw.strip() 42 if len(line) == 0: 43 continue 44 elif line[0] == '#': 45 continue 46 elif i_signif_line == 0: 47 # _RAJ2000;_DEJ2000;Name;RAJ2000;DEJ2000;Bmag;Vmag;SpType;FileName 48 col_names = line.split(';') 49 for i, col_name in enumerate(col_names): 50 out_dict['data_lists'][col_name] = [] 51 icol_to_colname[i] = col_name 52 elif i_signif_line == 1: 53 unit_str_list = line.split(';') 54 for i, unit_str in enumerate(unit_str_list): 55 out_dict['data_units_dict'][icol_to_colname[i]] = unit_str 56 elif i_signif_line == 2: 57 pass # skip this but also increment i_signif_line below 58 else: 59 elems = line.split(';') 60 for i, elem in enumerate(elems): 61 out_dict['data_lists'][icol_to_colname[i]].append(elem) 62 i_signif_line += 1 63 return out_dict
58 def read_tsv(self): 59 lines = [] 60 with self.annotation_file.open('r') as ann_file: 61 reader = csv.reader(ann_file, delimiter="\t", quotechar=None) 62 for idx, line in enumerate(reader): 63 if idx == 0: 64 continue 65 guid = "dev-{}".format(idx) 66 language = line[0] 67 if self.language_filter and language not in self.language_filter: 68 continue 69 label = reversed_label_map[line[1]] 70 text_a = line[6] 71 text_b = line[7] 72 lines.append(InputExample(guid, text_a, text_b, label)) 73 74 return lines