- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在向 CSV 文件写入一个函数(正在运行),但是它在最后一行中被中途切断。我知道这可能与文件的关闭有关,但我认为我做得正确。
有什么可能出错的地方吗?
from itertools import combinations as cb
import csv
import numpy as np
with open("usableReviewScores.csv") as f:
reader=csv.reader(f)
next(reader, None) # skip header
data=[filter(None,i) for i in reader]
writer = csv.writer(open("alexData1.csv", 'wb'))
def avgg(x):
ll=[float(i) for i in x[1:]] #take review no and convert to float
n=len(ll)
avg_list=[x[0]] #start result list with ref no.
final_list=[]
a = 0
b = []
c = []
d = []
global min_val
global max_val
min_val = 0
max_val = 0
for i in range(4,5):
for j in cb(ll,i):
# print(j)
c = i
avg_list.append(sum(j)/i)
final_list.append(sum(j)/i)
a = sum(final_list)/len(final_list)
min_val = min(final_list)
max_val = max(final_list)
d = np.std(final_list)
return (avg_list, "avg", a, "min", min_val, "max", max_val,
"Num of reviews", c, "std", d, "Total Reviews", n)
for x in data:
print(avgg(x))
for x in data:
writer.writerow(avgg(x))
最佳答案
你说这可能与文件的关闭有关。好吧,您实际上根本没有关闭输出文件。。所以我猜测这是文件系统缓存的症状,并且由于文件未关闭而缓存未正确刷新
您应该使用 with open(filename) 作为句柄:
进行书写和输入:
with open("alexData1.csv", 'wb') as outfile:
writer = csv.writer(outfile)
for x in data:
writer.writerow(avgg(x))
关于Python - CSV 写作 - 切断最后几行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43868218/
我正在尝试使用 http://fsprojects.github.io/ExcelProvider/ 中的 ExcelProvider .我不确定我是否遗漏了什么,但有什么方法可以实际编写 Excel
我正在用 C 编写程序,我想我在内存方面遇到了一些麻烦。 所以我的问题是:我有 2 个返回结构的函数。当我一次只运行一个函数时,我没有任何问题。但是当我一个接一个地运行时,我在写入第二个结构时总是会出
我正在使用以下代码通过 scrapey 抓取数据: from scrapy.selector import Selector from scrapy.spider import Spider clas
我偶然发现了文件处理问题, 第二行无缘无故为您提供9的值, 第三行给出错误io.UnsupportedOperation:不可读 c = open("Test.txt", "w+") c.write(
我正在向 CSV 文件写入一个函数(正在运行),但是它在最后一行中被中途切断。我知道这可能与文件的关闭有关,但我认为我做得正确。 有什么可能出错的地方吗? from itertools import
作为新用户,我设法制作了一个蜘蛛可以爬行的电子商务网站并提取每个产品的标题和变体以及输出的 CSV 文件和产品线,但我希望的是这是逐行的变化,请有人帮助我推进我的项目。 我很期待这个问题,但不幸的是我
我只是一个在业余时间编写 iOS 和 Andorid 应用程序的人。我有一些 Android 应用程序,我认为它们很适合进行更新,使它们能够在 Honeycomb 上本地运行。 但是,由于我没有 Ho
嘿,所以我并没有真正弄乱它太多,但我想知道是否真的有一种方法(在我陷入无休止的兔子洞之前)在 Dart/Flutter 中读取和写入 CSV 文件?我需要写入文件,不一定要读取它们,而且我愿意为此付出
当谈到 OCaml 时,我是一个完整的新手。我最近才开始使用该语言(大约 2 周前),但不幸的是,我的任务是为一种组合语言制作一个语法分析器(解析器 + 词法分析器,其功能是接受或不接受句子)使用门希
你能给我一些很好的引用资料吗,我可以如何通过 .net 资源读写注册表? 我查看了网站,找不到任何有用的信息。 最佳答案 检查 BCL 中的 Registry 类 http://msdn.micros
我正在开发一个可以生成大量数据并将其存储到磁盘的系统。该公司之前开发的一个系统使用普通文件来存储其数据,但由于多种原因,它变得非常难以管理。 我相信 NoSQL 数据库对我们来说是很好的解决方案。我们
如主题标题。当我写:void fun(int *tab){} 和写 void fun(int tab[]){} 一样吗? 最佳答案 是的。 void fun(int *tab){} void fun(
想不通此函数(用于将互联网站点抓取为 pdf 的类的一部分)应该合并使用 pypdf 从网页生成的 pdf 文件。 这是方法代码: def mergePdf(self,mainname,inputli
我是一名优秀的程序员,十分优秀!