df.sample(3).values[:,1:].astype('float64')
>> array([[ 1.31199997e+02, 1.37149994e+02, 1.31199997e+02,
1.36320007e+02, 1.17088593e+02, 6.15015000e+05],
[ 1.35199997e+02, 1.36570007e+02, 1.34330002e+02,
1.35639999e+02, 1.16504501e+02, 3.52835000e+05],
[ 1.31419998e+02, 1.33500000e+02, 1.30759995e+02,
1.31779999e+02, 1.13189064e+02, 2.09805000e+05]])
我正在使用 pandas 从 csv 文件中读取数据,然后将数据转换为numpy.float64但得到指数值,1.31199997e+02但预期的输出应该是正常的数字,131.199997而不是1.31199997e+02
我的代码:
df = pd.read_csv('data.csv') # reading csv
df.dtypes
>>
Date object
Open float64
High float64
Low float64
Close float64
Adj Close float64
Volume int64
dtype: object
a = df.sample(3).values[:,1:] # get array using `dataframe.values`
a
>> array([[131.199997, 137.149994, 131.199997, 136.320007, 117.08859299999999,
615015],
[135.199997, 136.570007, 134.330002, 135.639999, 116.504501, 352835],
[131.419998, 133.5, 130.759995, 131.779999, 113.18906399999999,
209805]], dtype=object)
a = a.astype('float64') # converting to `float64`
a
>> array([[ 1.31199997e+02, 1.37149994e+02, 1.31199997e+02,
1.36320007e+02, 1.17088593e+02, 6.15015000e+05],
[ 1.35199997e+02, 1.36570007e+02, 1.34330002e+02,
1.35639999e+02, 1.16504501e+02, 3.52835000e+05],
[ 1.31419998e+02, 1.33500000e+02, 1.30759995e+02,
1.31779999e+02, 1.13189064e+02, 2.09805000e+05]])
茅侃侃
慕田峪4524236
相关分类