这看起来很微不足道。一般来说,我会做以下事情:
results = []
reader = csv.reader(open('file.csv'))
for line in reader: # iterate over the lines in the csv
if line[1] in ['XXX','YYY','ZZZ']: # check if the 2nd element is one you're looking for
results.append(line) # if so, add this line the the results list
但是,我的数据集格式不是那么简单。它看起来如下:
Symbol,Values Date
XXX,8/2/2010
XXX,8/3/2010
XXX,8/4/2010
YYY,8/2/2010
YYY,8/3/2010
YYY,8/4/2010
ZZZ,8/2/2010
ZZZ,8/3/2010
ZZZ,8/4/2010
基本上我要做的是解析列表中每个唯一符号的第一个日期,以便我最终得到以下内容:
XXX,8/2/2010
YYY,8/2/2010
ZZZ,8/2/2010
答案 0 :(得分:1)
Pandas可能有所帮助。 ; - )
var express = require('express');
var router = express.Router();
router.post('/', (request, response) => {
// some stuff
});
module.exports = router;
答案 1 :(得分:0)
这是一个简单的解决方案,使用一组已经找到的第一个元素:
results = []
reader = csv.reader(open('file.csv'))
already_done = set()
for line in reader: # iterate over the lines in the csv
if line[1] in ['XXX','YYY','ZZZ'] and line[0] not in already_done:
results.append(line) # if so, add this line the the results list
already_done.add(line[0])