嗨im试图读取csv文件并将具体数据放入html表格并创建一个包含该表格的html页面。 我的csv文件有大约110行和5列,分别为“反对”,“赢家”,“边距”,“地面”和“年份”。列“年”包含2012年,2013年,2014年,2015年,2016年,2017年六个级别。我试图提取“年= 2012”的数据并创建一个包含我提取数据的html表格的html页面。 我的csv文件就像;使用python创建html页面
Opposition,Winner,Margin,Ground,Year
aa,mi,8runs,ab,2012
bb,bb,7runs,ac,2012
cc,cc,2runs,ab,2013
aa,aa,3runs,ac,2014
我需要2012年作为年份的行,在我的“2012.html”页面内作为表。 到目前为止,我的代码是:
infile = open("new.csv", "r")
data = []
for line in infile:
cols = line.split(",")
Oposition = cols[0]
Winner = cols[1]
Margin = cols[2]
Ground = cols[3]
Year = cols[4]
pair = (Oposition, Winner, Margin, Ground, Year)
data.append(pair)
infile.close()
out1 = open("2012.html", "w")
out1.write("""<!DOCTYPE html>
<html>
<head>
</head>
<body>
""")
for r in data:
if r["Year"] == "2012":
Oposition = r["Oposition"]
Winner = r["Winner"]
Margin = r["Margin"]
Year = r["Year"]
out1.write(" <p>" + c + " " + str(p) + "</p>\n")
out1.write(" </body>\n")
out1.write("</html>\n")
out1.close()
任何人帮助我。 非常感谢。 里面的2012年的HTML页面我需要一个表; sample table
并为获奖者列
究竟是什么问题? – JazZ
给我们一个简短的示例new.csv – Ahmad
即时尝试创建一个名为“2012.html”的html网页,并在该页面中创建一个包含“年= 2012”数据的表格。 – Dush