我想用字符“ 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:“ NoneType”对象没有属性“ iterrows”
答案 0 :(得分:1)
使用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_tagged = pd.read_csv("finalcolmnformat1.csv", sep =" ", encoding='utf-8')
ment_tagged = ment_tagged.fillna('O')
for row in ment_tagged.iterrows():
print(row)