Python 如何消除对数据帧使用iloc函数时出现的属性错误?

Python 如何消除对数据帧使用iloc函数时出现的属性错误?,python,pandas,data-science,Python,Pandas,Data Science,我试图根据iloc中的指定条件为列“fare_amount”设置0值,结果得到属性错误。”“数据集”是数据帧对象 AttributeError:“int”对象没有属性“loc” dataset = dataset.loc[dataset['fare_amount'] != 0 & dataset['passenger_count'] == 0, 'fare_amount'] = 0 有人能帮我吗?看看你在做什么 dataset = dataset.loc[dataset['fare_a

我试图根据iloc中的指定条件为列“fare_amount”设置0值,结果得到属性错误。”“数据集”是数据帧对象

AttributeError:“int”对象没有属性“loc”

dataset = dataset.loc[dataset['fare_amount'] != 0 & dataset['passenger_count'] == 0, 'fare_amount'] = 0

有人能帮我吗?

看看你在做什么

dataset = dataset.loc[dataset['fare_amount'] != 0 & dataset['passenger_count'] == 0, 'fare_amount'] = 0
您正在编写数据集==0。因此您将“=”放了两次。您应该这样做:

dataset.loc[dataset['fare_amount'] != 0 & dataset['passenger_count'] == 0, 'fare_amount'] = 0

这里的
dataset
是什么?这意味着变量
dataset
的类型是
int
。尝试
键入(数据集)
以确认并在上游找到问题。问题是您的第二个
=
赋值将整个设置为零,“数据集”是数据帧类型。这样做时,我得到的是
值错误:序列的真值不明确。使用a.empty、a.bool()、a.item()、a.any()或a.all()。