当我运行下面的代码时,我只获得了我的CSV文件的第一行(我的名字行)。我该怎么做才能确保下面的代码返回我的整个CSV?
em.executeQuery(query).then(function(data) {
entities = data.results;
entities.forEach(function(entity) {
// post-initialize the entity
// (it has already been merged into the cache)
});
return entities;
});
答案 0 :(得分:5)
read_csv
功能
df = pd.read_csv('elves.csv')
答案 1 :(得分:3)
返回总是立即退出循环。试试,例如。
def f():
for i in range(100):
return i
f()
你的流程应该是这样的:
with open('elves.csv') as csvjawn:
readCS = csv.reader(csvjawn, delimiter = ',')
data = [row for row in readCS]
这使用了一个列表理解,如果你以前没见过,你可能想要研究它。
答案 2 :(得分:-1)
我不会使用return
来完成你想要做的事情。
stackoverflow的同事(abarnert)的回应:
with open('old.csv', 'rb') as oldf, open('new.csv', 'wb') as newf:
old_reader = csv.reader(oldf)
writer = csv.writer(newt)
for row in old_reader:
writer.writerow(transform(row))
with open('new.csv', 'rb') as newf:
new_reader = csv.reader(newf)
for row in new_reader:
print row