# -*- coding: utf-8 -*-
import csv
import random
nomfichier="grosfichier2.csv"
tableau = []
with open(nomfichier, newline='') as csvfile:
objetcsv = csv.reader(csvfile, delimiter=',')
for ligne in objetcsv:
tableau.append(ligne)
def max_pt_date(points,date):
points = 0
for ligne in tableau:
if (ligne[1] == date):
if (int(ligne[3]) > points):
points = int(ligne[3])
return points
def listeDates():
dates = []
colonne = 1
for ligne in tableau:
if not (ligne[colonne] in dates) and ligne[colonne] != 'Date' :
dates.append(ligne[colonne])
return dates
def max_pt_dates_tot(date):
tout = []
lesDates = listeDates()
for date in lesDates:
tout.append([date,max_pt_date,(date)])
return tout
def toutlesmax():
tout = []
for date in listeDates():
tout.append(max_pt_dates_tot(date))
return tout
for ligne in toutlesmax():
print(ligne)
此代碼的目的是在 csv 檔案中查找每個日期的每個最大生產點,格式為:2022-04-20_11:58:02。該檔案包括多個月份和年份的日期。
代碼以我從未見過的方式回傳值,有人可以幫助我嗎?
uj5u.com熱心網友回復:
當您忘記在函式末尾添加 () 時,通常會發生這種情況。我想我在 max_pt_dates_tot 函式中看到了您的問題。max_pt_date 和 (date) 之間有一個逗號。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/479365.html
上一篇:Pytorch(2)-TensorBoard和Transforms的使用
下一篇:網頁抓取后將文本寫入csv
