使用python 2.7.5和pandas 0.12.0,我正在尝试使用'pd.io.parsers.read_fwf()'将固定宽度字体的文本文件导入到DataFrame中.我导入的值都是数字,但重要的是保留前导零,所以我想将dtype指定为字符串而不是int.
根据此函数的文档,read_fwf支持dtype属性,但是当我尝试使用它时:
data= pd.io.parsers.read_fwf(file, colspecs = ([79,81], [87,90]), header = None, dtype = {0: np.str, 1: np.str})
我收到错误:
ValueError: dtype is not supported with python-fwf parser
我已经尝试了尽可能多的变体,因为我可以设想'dtype = something',但它们都会返回相同的消息.
任何帮助将非常感激!