Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/132.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 3.x 为什么会出现此错误:AttributeError:';非类型';对象没有属性';iterrows';_Python 3.x - Fatal编程技术网

Python 3.x 为什么会出现此错误:AttributeError:';非类型';对象没有属性';iterrows';

Python 3.x 为什么会出现此错误:AttributeError:';非类型';对象没有属性';iterrows';,python-3.x,Python 3.x,我想用字符“O”替换csv文件中的空值,并且我的代码不会在现有csv文件中永久保存更改值 ment_tagged = pd.read_csv("finalcolmnformat1.csv", sep =" ", encoding='utf-8') ment_tagged= ment_tagged.fillna('O', inplace= True) for row in ment_tagged.iterrows(): print(row) A B C g a

我想用字符“O”替换csv文件中的空值,并且我的代码不会在现有csv文件中永久保存更改值

ment_tagged = pd.read_csv("finalcolmnformat1.csv", sep =" ", encoding='utf-8')
ment_tagged=  ment_tagged.fillna('O', inplace= True)
for row in ment_tagged.iterrows():
    print(row)

A    B    C
g    a    NULL
d    b    YES
x    v     NULL
预期输出值存储在相同的现有文件中,如下所示:

A    B    C
g    a    O
d    b    YES
x    v     O


for row in ment_tagged.iterrows():
AttributeError:“非类型”对象没有属性“ItErrors”


使用
inplace=True
fillna
返回
None
。切换到以下任一选项:

ment_tagged = pd.read_csv("finalcolmnformat1.csv", sep =" ", encoding='utf-8')
ment_tagged.fillna('O', inplace=True)
for row in ment_tagged.iterrows():
    print(row)


试试
ment\u taged=ment\u taged.fillna('O')
ment_tagged = pd.read_csv("finalcolmnformat1.csv", sep =" ", encoding='utf-8')
ment_tagged =  ment_tagged.fillna('O')
for row in ment_tagged.iterrows():
    print(row)