这家伙是怎么工作的,我只是对这件事很着迷。
1:首先使用python的默认类型:无法工作,rase错误
bins = pd.DataFrame(dtype=[str, int, int], columns=["chrom", "start", "end"])
raise error : TypeError: data type not understood2:使用numpy的dtype function.It确实有效,但结果是错误的。
bins = pd.DataFrame(dtype=np.dtype("str","int32","int32"), columns=["chrom", "start", "end"])
bins.dtypes
output:
chrom object
start object
end object
dtype: object发布于 2019-03-16 02:56:43
首先可以使用列名定义DataFrame,然后用.astype更改类型,如下所示:
bins = pd.DataFrame(columns=["chrom", "start", "end"])
bins = bins.astype({'chrom':'object',
'start':'int64',
'end':'int64'})
print(bins.dtypes)
chrom object
start int64
end int64
dtype: object注意事项:我使用object作为类型来定义字符串列,这是在pandas中定义text列的方式。
发布于 2019-03-16 05:00:06
dtype参数是将列名和dtype合并在一起的字典。
因此,对于您的情况,pd.Dataframe(dtype:{‘chron’:str,‘start’:np.int 33,‘end’:np.int 32)
https://stackoverflow.com/questions/55192954
复制相似问题