简单的问题 - 我正在执行以下操作:
train_set = pd.read_csv('./input/train_1.csv').fillna(0)
for col in train_set.columns[1:]:
train_set[col] = pd.to_numeric(train_set[col],downcast='integer')
数据帧的第一列是一个字符串 - 其余列是整数。Read_csv提供浮标,我不需要。缩减采样导致使用的 RAM 减少近 50%,但会显著减慢该过程。我可以一步到位地完成整个事情吗?或者有人知道如何多线程吗?
感谢
我建议您尝试这两个函数并再次查看性能:
-
读取文件时转换
# or uint8/int16/int64 depends on your data pd.read_csv('input.txt', sep=' ', dtype=np.int32) # or you can use converters with lambda function pd.read_csv('test.csv', sep=' ', converters={'1':lambda x : int(x)})
-
读取文件后转换数据帧
df['MyColumnName'] = df['MyColumnName'].astype(int)