只是想重申一下,这将适用于> = 0.9.1的熊猫:
In [2]: read_csv('sample.csv', dtype={'ID': object})Out[2]: ID0 000130078548178400166718681 000130078548178400167492512 000130078548178400167546303 000130078548178400167818764 000130078548178400170288245 000130078548178400179632356 00013007854817840018860166我也在创建一个有关检测整数溢出的问题。
编辑:在这里查看分辨率:https :
//github.com/pydata/pandas/issues/2247
更新,因为它可以帮助其他人:
要将 所有列都 设为str,可以执行此操作(根据评论):
pd.read_csv('sample.csv', dtype = str)要将 大多数或选择性的列 设为str,可以执行以下操作:
# lst of column names which needs to be stringlst_str_cols = ['prefix', 'serial']# use dictionary comprehension to make dict of dtypesdict_dtypes = {x : 'str' for x in lst_str_cols}# use dict on dtypespd.read_csv('sample.csv', dtype=dict_dtypes)


