简体   繁体   中英

Unable to change data types of certain columns read from xslx and by Pandas

I import an Excel file with pandas and when I try to convert all columns to float64 for further manipulation. I have several columns that have a type like:

0
column_name_1 float64
column_name_1 float64
dtype: object

and it is unable to do any calculations. May I ask how I could change this column type to float64?

If You want to change the datatype of columns in pandas,

Have you tried using the astype() function, Visit the official documentation below for more information and usage examples,

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.astype.html

I just solved it yesterday and it is because I have two same columns in the Data frame and it causes that when I try to access pd['something'] it automatically combine two columns together and then it becomes an object instead of float64

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM