Hello people of the web,
I am trying to transform a dataframe's column into a numpy array, yet I find myself having a weird issue I couldn't verbalise good enough in order to find any information to handle it.
The column 'height' is the one i'm trying to transform (the rightest column in the df) using to_numpy function, in the following way:
gives me the following result:
as you can notice in the 3rd image, to_numpy() has erased the rightest digit (the 0) from the heights while leaving the decimal period in place..
I have tried using astype(float) without success, in the following ways:
data.iloc[:, size_df].astype(float).to_numpy()
data.iloc[:, size_df].to_numpy().astype(float)
thanks in advance.
CodePudding user response:
So, as @hpaulj mentioned, it's just a representation of the same number. Following his advice, I printed the datatype, and I could see that it is still considered as a float:
print(data.iloc[:, size_df].to_numpy().dtype) // prints 'float64'
In order to get rid of the decimal point, I could cast, as @sj95126 suggested, to integer, by using
.to_numpy(dtype=int)
Thanks!
CodePudding user response:
Follo @dani_l_n advice. Also, in case of numpy
it would be better to cast to numpt dtypes rather than python data types like np.int32
, etc.