我有一个(每天都在增长的)大约100个大型excel文件的列表,我用Python进行分析。由于我必须在所有文件上运行几个循环,因此我的分析速度越来越慢。因此,我想将所有excel文件转换为feather格式(比如每周一次)。有没有聪明的办法?到目前为止,我所尝试的:
path = r"filepath\*_name*.xlsx"
file_list = glob.glob(path)
for f in file_list:
df = pd.read_excel(f, encoding='utf-8')
df[['boola', 'boolb']] = dfa[['boola', 'boolb']].astype(int)
pathname = f[:-5] + ".ftr"
df.to_feather(pathname)
但我收到以下错误消息:
ArrowInvalid: ('Could not convert stringa with type str: tried to convert to boolean', "Conversion failed for column stringb with type object")
以下是解决我问题的方法:
, decimal=',', thousands='.'
部分是必需的,因为我的输入文件是按照欧洲标准格式化的,即使用逗号作为十进制分隔符,使用点作为千位分隔符实际上,您会遇到这个问题,因为名为
"stringa,stringb"
的列有一些feather无法确定的字符,他试图转换为其他类型,但返回了错误, 因此,对于我以前遇到的相同问题,我的解决方案是首先将列转换为字符串,并替换导致错误的字符 此外:注意:我认为pd.read_excel不需要按照documentation进行参数编码
相关问题 更多 >
编程相关推荐