How to use 'pandas read tsv' in Python

Every line of 'pandas 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
26def 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))
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

37def readcsv(filename, header=True):
38 return pd.read_csv(filename, header=None) if not header else pd.read_csv(filename)

Related snippets