python mapreduce - 跳过 mapper 中 .csv 的第一行

python mapreduce - Skipping the first line of the .csv in mapper

我正在尝试在 python 中进行 mapreduce,我的 csv 文件如下所示,

    trip_id taxi_id pickup_time dropoff_time ... total
0   20117   2455.0  2013-05-05   09:45:00         50.44
1   44691   1779.0  2013-06-24   11:30:00         66.78

我的代码是,

import pandas as pd
import numpy as np
from mrjob.job import MRJob

class MRCount(MRJob):

def mapper(self, _, line):
    datarow = line.replace(' ','').replace('N/A','').split(',')
    trip_id = datarow[0]
    total = datarow[14]
    total = np.float(total)
    yield ((trip_id), (total))

因为我的代码将所有行都传递给映射器,所以它以字符串行(索引)开始,但我想玩总计,它是浮点数,所以当我 运行 文件时,它得到一个错误

TypeError: float() argument must be a string or a number, not 'generator'

处理mapper函数时如何跳过csv文件的第一行?

不确定 'line' 的确切内容。一个简单的答案就是 try/except 浮动。

def mapper(self, _, line):
    datarow = line.replace(' ','').replace('N/A','').split(',')
    trip_id = datarow[0]
    total = datarow[14]
    try:
        total = np.float(total)
    except TypeError:
        print("skipping line with value", datarow[14])
    else:
        yield ((trip_id), (total))