How the object format is lossless converted to float64 format

Source: Internet
Author: User
This time to everyone to bring the object format how lossless conversion to float64 format, the object format lossless conversion into the float64 format of the note, the following is the actual case, together to see.

In the process of data processing

For example, importing data from a CSV file

DATA_DF = Pd.read_csv ("Names.csv")

Be sure to look at the type of data before you process it

Data_df.info ()
*rangeindex:891 entries, 0 to 890 Data columns (total columns): Name 891 Non-null Object Sex 891 Non-null Object age 7  Non-null float64 sibsp 891 non-null Int64 parch 891 non-null Int64 Ticket 891 Non-null object Fare 891 non-null float64 Cabin 204 Non-null Object embarked 889 Non-null object Dtypes:float64 (2), Int64 (5), Object (5) Memory usage:83.6+ kb*

The above object, int64, and float64 are the types of data.

If we need to do an operation on the column data, it is important to note that:

Whether the data type of the two columns is the same!!

If an object type is added to the int64 type, an error occurs

The error message may be as follows:

Typeerror:ufunc ' Add ' not contain a loop with signature matching types Dtype (' <u32 ') dtype (' <u32 ') dtype (' <u32 ')

The type of object at this time may be ' 12.3 ' such as the number in STR format, if the operation must be formatted to convert:

The following methods can be used (convert_objects):

DT_DF = Dt_df.convert_objects (convert_numeric=true)

The pro-test is effective.

I'll remind you again! Get the data must first look at the data type!!!

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

How object is converted to float data

Vue2 How to implement bidirectional binding of parent and child components

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.