Home > Article > Backend Development > How to convert object format to float64 format losslessly
This time I will bring you object format lossless conversion to float64 format, object format lossless conversion to float64 format What are the precautions, the following is a practical case, let's come together take a look.
In the process of data processing
For example, importing data from a CSV file
data_df = pd.read_csv("names.csv")
Be sure to check the type of data before processing
data_df.info()
*RangeIndex: 891 entries, 0 to 890 Data columns (total 12 columns): Name 891 non-null object Sex 891 non-null object Age 714 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 perform operations on column data, one thing we must pay attention to is:
Whether the data types of the two columns are the same !!
If an object class type is added to an int64 type, an error will occur
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 object type at this time may be a number in str format like '12.3'. If you want to perform operations, format conversion must be performed:
can be used as follows Method (convert_objects):
dt_df = dt_df.convert_objects(convert_numeric=True)
Personal test is valid.
Remind me again! Before getting data, be sure to check the data type first! ! !
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:
How to convert object into float data
How to bidirectionally bind Vue2 parent component and child component accomplish
The above is the detailed content of How to convert object format to float64 format losslessly. For more information, please follow other related articles on the PHP Chinese website!