4 examples of 'read all csv files in folder python' in Python

Every line of 'read all csv files in folder python' 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
146def get_data_from_file(csv_content, files):
147 # Get description or fix from the file reference parsed in JsonToCsv class
148 data = ''
149 number_from_file = re.search('\d+', csv_content)
150 if not number_from_file:
151 return data
152 else:
153 file_number = number_from_file.group()
154
155 if file_number in files['filenames']:
156 filename = files['filenames'][file_number]
157 else:
158 return data
159
160 with open(path.join(files['path'], filename)) as file_object:
161 data = file_object.read()
162
163 return data
218def _find_all_csv_paths(input_path, house_id, year):
219 """
220 Returns
221 -------
222 list of csv paths of data (with respect to a house and a particular year )
223 """
224 house_year_path = (input_path + '/' + 'Home' + house_id + '/' + year)
225 extension = 'csv'
226 os.chdir(house_year_path)
227 csv_names = glob.glob(house_year_path + '/*.csv')
228
229 txt_paths = glob.glob(house_year_path + '/*.txt')
230
231 paths = []
232 # Take only those csv files which have 30 minutes as sample period
233 for txt_path in txt_paths:
234 f = open(txt_path, "r")
235 lines = f.readlines()
236 f.close()
237 if '30' in lines[-2]:
238 name_temp = lines[0].strip('\n')
239 paths.append(
240 house_year_path +
241 '/' +
242 name_temp +
243 '_' +
244 year +
245 '.csv')
246
247 return paths
10def read_stock_csv(stock_dir):
11 for filename in os.listdir(stock_dir):
12 #logger.info("start :%s" % filename)
13 code = filename.split('.')[0]
14 d_table_name = "%s_D" % code
15 stock = CStock(code, ct.DB_INFO)
16 #logger.info("created :%s" % filename)
17 try:
18 df = pd.read_csv(os.path.join(stock_dir, filename))
19 except pd.errors.EmptyDataError:
20 logger.info("%s:empty data" % code)
21 continue
22 df.columns = ['cdate', 'open', 'high', 'low', 'close', 'volume', 'amount']
23 #logger.info("readcsv :%s" % filename)
24 if not stock.mysql_client.set(df, d_table_name):
25 logger.info("failed :%s" % filename)
26 succeed_list.append(filename)
27 logger.info("succeed :%s" % filename)
51def load_csv_file(csv_file_path):
52 lines = get_lines_from_csv_file(csv_file_path)
53
54 scores = []
55 for line in lines[1:]:
56 begin = 0
57 for strategy in STRATEGIES:
58 score = [strategy] + map(int, line[begin: begin + 4])
59 begin += 4
60 scores.append(score)
61
62 return scores, CLASSIFICATIONS

Related snippets