我在pandas中有一些数据,我试图保存为32位浮点数,但我总是得到64位浮点数.我最好的尝试是这样的:
df['store'] = pd.DataFrame(data).astype(float32)
但它不起作用..任何想法?
解决方法:
使用numpy.float32:
In [320]:
import numpy as np
import pandas as pd
df = pd.DataFrame({'a':np.random.randn(10)})
df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 10 entries, 0 to 9
Data columns (total 1 columns):
a 10 non-null float64
dtypes: float64(1)
memory usage: 160.0 bytes
In [323]:
df['a'].astype(np.float32)
Out[323]:
0 0.966618
1 -0.331942
2 0.906349
3 -0.089582
4 -0.722004
5 0.668103
6 0.230314
7 -1.707631
8 1.806862
9 1.783765
Name: a, dtype: float32
你可以看到dtype现在是float32
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。