How to convert object to float data

php中世界最好的语言
Release: 2018-04-12 09:25:43
Original
15949 people have browsed it

This time I will bring you objectHow to convert object to float data, what are the precautions for converting object to float data, the following is a practical case, let's take a look.

DataType conversion:

I encountered a problem today, that is, the DataFrame type data is of str type Number, I want to convert the number to int or float; Baidu did not find a good one, or the keyword entered is wrong and cannot be found;

After DataFrame.info(), I found that the data are all objects

There was a previous method:

First traindata=np.array(traindata,dtype=np.float) Afterwards, I converted

traindata=pd.DataFrame(traindata)

but it looked very cumbersome, so on a whim, I tried the following method, and it was done in one sentence

traindata=pd.DataFrame(traindata,dtype=np.float); the float inside can also be replaced by int. I think other methods will work, but I haven’t tried it!

Enter DataFrame.info() to try again, all objects will become int, and you’re done!

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

2018 Summary of PHP practical development functions

v-for iteration syntax diagram in Vue2.0 The article explains in detail

How to use the index index of v-for in html

The above is the detailed content of How to convert object to float data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!