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 iterableSolved
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)错误调用


![[Solved] Pandas--TypeError: ‘bool‘ object is not iterable [Solved] Pandas--TypeError: ‘bool‘ object is not iterable](http://www.mshxw.com/aiimages/31/487360.png)
