4 examples of 'numpy read csv' in Python

Every line of 'numpy read csv' 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

41def read_csv_file(file_name):
42 """
43 Return patient ID and sinogram array produced by reading a RayStation sinogram
44 CSV file with the provided file name.
45
46 Files are produced by ExportTomoSinogram.py, Brandon Merz,
47 RaySearch customer forum, 1/18/2018.
48
49 Format:
50 First row contains demographics. Subsequent rows correspond to couch positions.
51 Leaf-open time range from zero to one.
52 "Patient name: ANONYMOUS^PATIENT, ID: 00000",,,,,,,,,
53 ,0,0,0,0,0,0,0,0,0,0,0,0,0.39123373,0.366435635 ...
54 """
55
56 with open(file_name, 'r') as csvfile:
57
58 pat_name, pat_num = csvfile.readline().split('ID:')
59 pat_name = pat_name.replace('Patient name:', '')
60
61 pat_name_last, pat_name_first = pat_name.split('^')
62 pat_name_last = ''.join([c for c in pat_name_last if c in LETTERS])
63 pat_name_first = ''.join([c for c in pat_name_first if c in LETTERS])
64 pat_num = ''.join([c for c in pat_num if c in DIGITS])
65
66 document_id = pat_num + ' - ' + pat_name_last + ', ' + pat_name_first
67 reader = csv.reader(csvfile, delimiter=',')
68 array = np.asarray([line[1:] for line in reader]).astype(float)
69
70 return document_id, array
11def read_csv(array, filename):
12 with open(filename, 'rb') as input_file:
13 foo = csv.reader(input_file)
14 for row in foo:
15 array.append(row)
16 return array
396def _load_raw_rates(self, file_path, sep):
397 """In MovieLens, the rates have the following format
398
399 ml-100k
400 user id \t movie id \t rating \t timestamp
401
402 ml-1m/10m
403 UserID::MovieID::Rating::Timestamp
404
405 timestamp is unix timestamp and can be converted by pd.to_datetime(X, unit='s')
406
407 Parameters
408 ----------
409 file_path : str
410
411 Returns
412 -------
413 rating_info : pd.DataFrame
414 """
415 rating_info = pd.read_csv(
416 file_path, sep=sep, header=None,
417 names=['user_id', 'movie_id', 'rating', 'timestamp'],
418 dtype={'user_id': np.int32, 'movie_id' : np.int32,
419 'ratings': np.float32, 'timestamp': np.int64}, engine='python')
420 return rating_info

Related snippets