[Solved] Pandas--TypeError: ‘bool‘ object is not iterable
[Solved] Pandas–TypeError: ‘bool’ object is not iterableimport pandas as pddf = pd.read_csv(ori_file_name, names=['img_name','label'])df.to_csv(new_file_name, index=False, columns= False)报错:df.to_csv(
·
[Solved] Pandas–TypeError: ‘bool’ object is not iterable
import pandas as pd
df = pd.read_csv(ori_file_name, names=['img_name','label'])
df.to_csv(new_file_name, index=False, columns= False)
报错:
df.to_csv(new_file_name, index=False, columns= False)
TypeError: 'bool' object is not iterable
Solved
bool 类型的数据不可迭代,就说明采用布尔值的地方出错了,通过查找源代码,发现columns=None 或者列表赋值,因而columns=False 会导致错误,正确代码如下:
import pandas as pd
df = pd.read_csv(ori_file_name, names=['img_name','label'])
df.to_csv(new_file_name, index=False, columns= ['img_name','label'])
#df.to_csv(new_file_name, index=False ) #或者采用默认值
小结:
这种错误的排查有两个思路
1)数据本身问题
2)错误调用
更多推荐
已为社区贡献1条内容
所有评论(0)