Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中CSV文件的列总和_Python_Csv - Fatal编程技术网

python中CSV文件的列总和

python中CSV文件的列总和,python,csv,Python,Csv,我有一个csv文件,我想找到运动员跑的总距离。CSV文件如下所示,如何在第3列中添加数字 使用pandas模块,它可能看起来像(或多或少) 使用pandas模块,它可能看起来像(或多或少) 下面是一种使用内置csv模块的方法 import csv csv_file = csv.reader(open("your_file_name.csv")) dist = 0 for row in csv_file: _dist = row[2] try: _dist =

我有一个csv文件,我想找到运动员跑的总距离。CSV文件如下所示,如何在第3列中添加数字


使用
pandas
模块,它可能看起来像(或多或少)


使用
pandas
模块,它可能看起来像(或多或少)


下面是一种使用内置csv模块的方法

import csv
csv_file = csv.reader(open("your_file_name.csv"))

dist = 0
for row in csv_file:
    _dist = row[2]
    try: 
        _dist = float(_dist)
    except ValueError:
        _dist = 0

    dist += _dist

下面是一种使用内置csv模块的方法

import csv
csv_file = csv.reader(open("your_file_name.csv"))

dist = 0
for row in csv_file:
    _dist = row[2]
    try: 
        _dist = float(_dist)
    except ValueError:
        _dist = 0

    dist += _dist

你没有提供足够的信息。你被困在哪里?读取文件有问题吗?求和是问题吗?问题是您没有尝试任何操作吗?我打开文件以便阅读,但我不知道如何选择特定列并添加值向我们显示您正在做什么intervals=(打开(“RunningIntervals.csv”,“r”))#我不知道在这里写什么,兄弟,这就是为什么我问如何做:/intervals.close()使用
pandas
模块,您只需使用2-3行代码即可,因为您没有提供足够的信息。你被困在哪里?读取文件有问题吗?求和是问题吗?问题是您没有尝试任何操作吗?我打开文件以便阅读,但我不知道如何选择特定列并添加值向我们显示您正在做什么intervals=(打开(“RunningIntervals.csv”,“r”))#我不知道在这里写什么,兄弟,这就是为什么我问如何做:/intervals.close()使用
pandas
module,只需2-3行代码即可。名为pandasIt的模块不是标准库。您必须安装-
pip安装pandas
名为pandasIt的模块不是标准库。你必须安装-
pip install pandas
是的,这对我来说很有效,谢谢,但是如果我也想知道总时间呢?我试过同样的方法,但时间变为零。但当我删除距离代码时,它会正确地找到总时间。我该怎么做才能找到这两个呢?是的,这对我很有用,谢谢,但是如果我也想找到总时间呢?我试过同样的方法,但时间变为零。但当我删除距离代码时,它会正确地找到总时间。我怎样才能找到他们两个?