10 examples of 'read text file python pandas' in Python

Every line of 'read text file python pandas' 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
39def _load_text(text_path):
40 with open(text_path + '.txt', 'r', encoding='utf-8') as fin:
41 text = ' '.join([line.strip() for line in fin.readlines()])
42 return text
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

29def read_text_file(filename, encoding="utf-8"):
30 """
31 Reads a file under python3 with encoding (default UTF-8).
32 Also works under python2, without encoding.
33 Uses the EAFP (https://docs.python.org/2/glossary.html#term-eafp)
34 principle.
35 """
36 try:
37 with open(filename, 'r', encoding) as f:
38 r = f.read()
39 except TypeError:
40 with open(filename, 'r') as f:
41 r = f.read()
42 return r
28def read_text(filename, **kwargs):
29 """read_text"""
30 memory = kwargs.get("memory", "")
31 offset = kwargs.get("offset", 0)
32 length = kwargs.get("length", -1)
33 return core_ops.io_read_text(
34 filename, offset=offset, length=length, memory=memory)
12def readFile():
13 #make the format of the csv file. Our format is a vector with 13 features and a label which show the condition of the
14 #sample hc/pc : helathy case, parkinson case
15 names = ['Feature1', 'Feature2', 'Feature3', 'Feature4','Feature5','Feature6','Feature7','Feature8','Feature9',
16 'Feature10','Feature11','Feature12','Feature13','Label']
17
18 #path to read the samples, samples consist from healthy subjects and subject suffering from Parkinson's desease.
19 path = ''
20 #read file in csv format
21 data = pd.read_csv(path,names=names )
22
23 #return an array of the shape (2103, 14), lines are the samples and columns are the features as we mentioned before
24 return data
20def readFile():
21 #make the format of the csv file. Our format is a vector with 13 features and a label which show the condition of the
22 #sample hc/pc : helathy case, parkinson case
23 names = ['Feature1', 'Feature2', 'Feature3', 'Feature4','Feature5','Feature6','Feature7','Feature8','Feature9',
24 'Feature10','Feature11','Feature12','Feature13','Label']
25
26 #path to read the samples, samples consist from healthy subjects and subject suffering from Parkinson's desease.
27 path = 'mfcc_multiclass.txt'
28 #read file in csv format
29 data = pd.read_csv(path,names=names )
30
31 #return an array of the shape (2103, 14), lines are the samples and columns are the features as we mentioned before
32 return data
141def readFile(pFile):
142 return pd.read_csv(pFile, sep='\t', header=None)
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
37def readcsv(filename, header=True):
38 return pd.read_csv(filename, header=None) if not header else pd.read_csv(filename)
1def read_text_src(text_src, delimiter):
2 if isinstance(text_src, str):
3 with open(text_src, 'r') as f:
4 text_src = [line.split(delimiter) for line in f]
5 elif not isinstance(text_src, list):
6 raise TypeError('text_src should be list or str')
7 return text_src
17def raw_reader(path):
18 with open(path, 'rb') as f:
19 bin_data = f.read()
20 return bin_data

Related snippets