一些关于表格bug的归纳速查(1)

TypeError: ‘NoneType’ object is not iterable
返回值为None,但接收有好几个值,例如:

def foo():
	return None

a, b = foo()

pandas.core.indexing.IndexingError: Too many indexers
df.loc[:,'风力','天气']应改为df.loc[:,['风力','天气']]

IndexError: single positional indexer is out-of-bounds

df = pd.DataFrame(np.arange(12).reshape(3,4)%4)
print(df.iloc[4])

IndexError: iloc cannot enlarge its target object
在想要把值赋给新的行时会出现这个问题,例如:

for i in sheet.nrows:
	df.iloc[i] = sheet.row_values(i)

应该为

for i in sheet.nrows:
	df.loc[i] = sheet.row_values(i)

KeyError: “[‘lalala‘] not found in axis“
在删除行或列时经常一不注意就把名字写错,会报这个错

猜你喜欢

转载自blog.csdn.net/skywuuu/article/details/112762185