我一直在尝试使用一个函数剥离多个数据帧中的所有字符串列 这是密码
def stripped_data(data):
data=data.apply(lambda x: x.str.strip() if x.dtype=="object" else x)
return data
然后我尝试使用locals()字典在同一个函数中传递多个表
for i in files_new:
locals()[i]=stripped_data(locals()[i])
这里是包含表名的列表 但这就是错误——“只能使用带字符串值的.str访问器!”
但是这段代码单独运行时没有任何错误
data=data.apply(lambda x: x.str.strip() if x.dtype=="object" else x)
其中data是任何表的名称
目前没有回答
相关问题 更多 >
编程相关推荐