2024-09-27 04:24:43 发布
网友
我有5000行的excel文件,每行有17000列,可以选择使用python/pandas拆分此文件,因为现在当我尝试读取excel时,它返回MemoryError 如果我能以某种方式读取文件,我可以减少列数
drop(list(myFile.filter(regex=r'(x|y)')))
有人能帮我怎么做吗
在pandas中,您需要设置参数,并且应该为csv列指定数据类型。 比如说
low_memory= False
df = pd.read_csv("YOURFILENAME.csv", delimiter = '|',error_bad_lines=False, index_col=False, dtype='unicode') # , # This or the other one #dtype={"user_id": int, "username": "string"}, low_memory = False)
最好的做法是为各个列指定数据类型,以防因为案例中有大量列而无法指定。您只需使用Try,第二列除外,并遍历值(如果string有string,如果int8有int 8,如果int64有相同的方式)
编辑:在读取excel时指定Unicode
查看read_excel中的usecols参数
usecols
在pandas中,您需要设置参数,并且应该为csv列指定数据类型。 比如说
最好的做法是为各个列指定数据类型,以防因为案例中有大量列而无法指定。您只需使用Try,第二列除外,并遍历值(如果string有string,如果int8有int 8,如果int64有相同的方式)
编辑:在读取excel时指定Unicode
查看read_excel中的
usecols
参数相关问题 更多 >
编程相关推荐