我试图减少内存使用量,然后使用了以下代码:
https://www.kaggle.com/arjanso/reducing-dataframe-memory-size-by-65/notebook
并将列名和列类型保存到pickle文件中,以便从csv读取时,我可以如下自动转换类型:
pkl_in = open('explore/col_types.pkl', "rb")
col_types = pickle.load(pkl_in)
pkl_in = open('explore/col_names.pkl', "rb")
mcol_names = pickle.load(pkl_in)
test_data=pd.read_csv('bb.csv',usecols=col_names,dtype=col_types,nrows=100)
但是它显示了错误:
ValueError: cannot safely convert passed user dtype of uint32 for float64 dtyped data in column 16
阅读csv时我可以知道如何强制转换为类型吗?