3 examples of 'pandas read_txt' in Python

Every line of 'pandas read_txt' 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
37def readcsv(filename, header=True):
38 return pd.read_csv(filename, header=None) if not header else pd.read_csv(filename)
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

10def __read(filename):
11 field_names = ['date', 'value', 'metaID']
12 entry_format = '<qdi' # long, double, int; See field names above.
13 entry_size = calcsize(entry_format)
14
15 if not os.path.exists(filename):
16 return pd.DataFrame(None, columns = ['date', 'value', 'metaID'])
17
18 records = np.fromfile(filename, dtype=np.dtype({'names':field_names, 'formats': entry_format[1:]}))
19
20 if len(records) == 0: return pd.DataFrame(None, columns = ['date', 'value', 'metaID'])
21
22 df = pd.DataFrame(records, columns = field_names)
23 df['date'] = pd.to_datetime(df['date'], unit='s')
24 df = df.set_index('date')
25
26 meta_ids = df.metaID
27 df.loc[df.metaID == METADATA_MISSING_VALUE] = np.nan
28 df.metaID = meta_ids
29
30 return df
8def read_txt(txt):
9 f = open(txt, 'r')
10 lines = f.readlines()
11 f.close()
12 return [tmp.strip() for tmp in lines]

Related snippets