“过滤器”对象不可下标

时间:2019-05-10 07:28:51

标签: python-3.x

我想删除二维列表中具有空值的数据集。

from random import seed
from random import randrange
from csv import reader
from math import sqrt
from pandas import *
from numpy import *
# Load a CSV file
def load_csv(filename):
    dataset = list()
    with open(filename, 'r') as file:
        csv_reader = reader(file)
        for row in csv_reader:
            if not row:
                continue
            dataset.append(row)
    return dataset
# Convert string column to float
def str_column_to_float(dataset, column):
    for row in dataset:
        row[column] = float(row[column].strip())

filename="insurance.csv"
dataset=load_csv(filename)
#mdataset=[x for x in dataset if x]
mdataset=filter(None,dataset)
for i in range(len(mdataset[0])):
    str_column_to_float(mdataset, i)

它抛出了'filter' object is not subscriptable

的错误

0 个答案:

没有答案