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]])
Я читаю данные из CSV-файла, используя pandas, затем преобразую данные в 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]])
data.csv
Date,Open,High,Low,Close,Adj Close,Volume
2013-05-08,135.199997,136.570007,134.330002,135.639999,116.504501,352835
2013-05-09,135.800003,138.940002,135.199997,136.259995,117.037041,952515
2013-05-10,136.199997,138.199997,135.009995,135.389999,116.289780,444045
2013-05-13,135.000000,136.000000,131.639999,132.539993,113.841843,260395
2013-05-14,131.419998,133.500000,130.759995,131.779999,113.189064,209805
2013-05-15,131.199997,137.149994,131.199997,136.320007,117.088593,615015